148 lines
5.3 KiB
C#
148 lines
5.3 KiB
C#
namespace VECV_WebApi.Controllers.Van
|
|
{
|
|
#region Namespaces
|
|
|
|
using LoggingHelper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
using VECV_WebApi.Models.Van;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// This controller contain van releted apis
|
|
/// </summary>
|
|
public class VanController : ApiController
|
|
{
|
|
#region Global Variable
|
|
|
|
/// <summary>
|
|
/// making object of LoggingUtility class available to this class
|
|
/// </summary>
|
|
LoggingUtility objLog = new LoggingUtility();
|
|
|
|
/// <summary>
|
|
/// making the data-log file path available to this class
|
|
/// </summary>
|
|
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
|
|
|
|
/// <summary>
|
|
/// making data log file path available to this class
|
|
/// </summary>
|
|
string logtf = (ConfigurationManager.AppSettings["Log"]);
|
|
|
|
/// <summary>
|
|
/// making error log file path available to this class
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
|
|
|
|
#endregion
|
|
|
|
|
|
#region APIs
|
|
|
|
/// <summary>
|
|
/// To get van postion detail with van detail
|
|
/// </summary>
|
|
/// <param name="model">van info</param>
|
|
/// <returns>status and data</returns>
|
|
public List<VanModel> Post([FromBody]GetVanPositionModel model)
|
|
{
|
|
// write data log into file
|
|
|
|
List<VanModel> objList = new List<VanModel>();
|
|
VanModel objVanModel = new VanModel();
|
|
try
|
|
{
|
|
VanRepository objVanRepository = new VanRepository(_connStr);
|
|
objList = objVanRepository.GetVanPositionDetail(model);
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("VanController post method no parameter", Ex.Message, path, errorlogtf);
|
|
|
|
objVanModel.Status = "0";
|
|
objVanModel.Message = Ex.Message;
|
|
objList.Add(objVanModel);
|
|
}
|
|
return objList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// To get/insert van coverage
|
|
/// </summary>
|
|
/// <param name="InsertGetVanPosition">extra param to identify the api</param>
|
|
/// <param name="InsertGetVanPosition1">extra param to identify the api</param>
|
|
/// <param name="model">coverage info</param>
|
|
/// <returns>status and data</returns>
|
|
public InsertGetVanPositionCoverage Post([FromUri]string InsertGetVanPosition, [FromUri]string InsertGetVanPosition1, [FromBody]InsertGetVanPositionCoverage model)
|
|
{
|
|
// write data log into file
|
|
|
|
InsertGetVanPositionCoverage objList = new InsertGetVanPositionCoverage();
|
|
try
|
|
{
|
|
VanRepository objVanRepository = new VanRepository(_connStr);
|
|
JavaScriptSerializer jss = new JavaScriptSerializer();
|
|
model.Coverage = jss.Deserialize<List<VanPositionCoverage>>(model.CoverageJson);
|
|
objList = objVanRepository.InsertGetVanPosition(model);
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("VanController post method no parameter", Ex.Message, path, errorlogtf);
|
|
|
|
objList.Status = "0";
|
|
objList.Message = Ex.Message;
|
|
}
|
|
return objList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// To update van postion detail/ van coverage
|
|
/// </summary>
|
|
/// <param name="updateVanPosition">extra param to identify the api</param>
|
|
/// <param name="model">extra param to identify the api</param>
|
|
/// <returns>status and data</returns>
|
|
public GetVanPositionModel post([FromUri]string updateVanPosition, [FromBody]GetVanPositionModel model)
|
|
{
|
|
// write data log into file
|
|
|
|
GetVanPositionModel objModel = new GetVanPositionModel();
|
|
try
|
|
{
|
|
VanRepository objVanRepository = new VanRepository(_connStr);
|
|
List<VanModel> objList = new List<VanModel>();
|
|
JavaScriptSerializer jss = new JavaScriptSerializer();
|
|
objList = jss.Deserialize<List<VanModel>>(model.VanListJson);
|
|
model.VanList = objList;
|
|
objModel = objVanRepository.UpdateVanPositionDetail(model);
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("VanController post method with one parameter", Ex.Message, path, errorlogtf);
|
|
|
|
objModel.State = "0";
|
|
objModel.Message = Ex.Message;
|
|
}
|
|
return objModel;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|