namespace VECV_WebApi.Controllers.Customer
{
#region Namespces
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 VECV_WebApi.Models.Customer;
#endregion
///
/// This controller
/// apis related to customer
///
public class CustomerController : ApiController
{
#region Global Variable
///
/// making object of LoggingUtility class available to this class
///
LoggingUtility objLog = new LoggingUtility();
///
/// making the data-log file path available to this class
///
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
///
/// making data log file path available to this class
///
string logtf = (ConfigurationManager.AppSettings["Log"]);
///
/// making error log file path available to this class
///
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
///
/// making Customer Repository object available to this class
///
CustomerRepository objCustomerRepository;
///
/// making the Database connection string available to this class
///
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
#endregion
#region APIs
///
/// To Insert new customer
///
/// Customer detail
/// Status details
public CustomerModel Post([FromBody]NewCustomerModel model)
{
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objModel = objCustomerRepository.InsertNewCustomerDetail(model);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("InsertNewCustomerDetail_Controller", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To insert get Owner detail
///
/// Extra parameter to identify the API
/// Owner id detail
/// Owner details
public CustomerModel Post([FromUri]string customer, [FromBody]CustomerModel model)
{
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objModel = objCustomerRepository.GetOwnerDetail(model);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("GetOwnerDetail_Controller", Ex.Message, path, errorlogtf);
return objModel;
}
}
public CustomerModel Get(string token, string KamUser, string CustomerId, string CustomerType,string CustomerCustomerName, string RegistrationNo,string CustomerMobileNumber1, string VehicleNumberPlate, string VehicleType, string modelnumber)
{
NewCustomerModel model = new NewCustomerModel();
model.Token = token;
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objModel = objCustomerRepository.InsertNewCustomerDetailDBMByPass(token, RegistrationNo, VehicleNumberPlate, CustomerMobileNumber1, modelnumber, KamUser, VehicleType, CustomerCustomerName);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("InsertNewCustomerDetail_Controller", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To get owner or customer complete detail
///
/// Extra parameter to identify the API
/// Customer/Owner Id information
/// Customer/Owner complete details
public List post([FromUri]string owner, [FromBody]CustomerModel model)
{
List objList = new List();
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objList = objCustomerRepository.GetOwnerCompleteDetails(model);
return objList;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("GetOwnerDetail_Controller", Ex.Message, path, errorlogtf);
objList.Add(objModel);
return objList;
}
}
///
/// To check customer or vehicle exist or not
///
/// extra parameter to identify the API
/// extra parameter to identify the API
/// customer iformation
/// customer details
public CustomerModel Post([FromUri]string owner,[FromUri]string type, [FromBody]CustomerModel model)
{
// write data log into file
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objModel = objCustomerRepository.CheckOwnerDetailExist(model);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("CustomerController CheckOwnerDetailExist", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To insert new owner with multiple customer or vehicle
///
/// extra param to identify the api
/// extra param to identify the api
/// extra param to identify the api
/// customer/vehicle details with owner info
/// statas details
public CustomerModel Post([FromUri]string customer, [FromUri]string owner, [FromUri]string vehicle, [FromBody]NewCustomerModel model)
{
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
objModel = objCustomerRepository.InsertOwnerCustomerVehicle(model);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("CustomerController InsertOwnerCustomerVehicle", Ex.Message, path, errorlogtf);
return objModel;
}
}
///
/// To get owner or customer complete detail
///
/// Extra parameter to identify the API
/// Customer/Owner Id information
/// Customer/Owner complete details
public List post([FromUri]int regNos, [FromBody]CustomerModel model)
{
List oListVehicleRegNos = new List();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
oListVehicleRegNos = objCustomerRepository.GetVehicleRegNoListByCustomerId(model);
return oListVehicleRegNos;
}
catch (Exception Ex)
{
throw Ex;
}
}
#endregion
///
/// To update customer
///
/// Customer detail
/// Status details
public CustomerModel Post([FromUri]string updatecustomer, [FromBody]NewCustomerModel model)
{
CustomerModel objModel = new CustomerModel();
try
{
objCustomerRepository = new CustomerRepository(_connStr);
// objModel = objCustomerRepository.InsertNewCustomerDetail(model);
objModel = objCustomerRepository.UpdateCustomerDetail(model);
return objModel;
}
catch (Exception Ex)
{
// write error log into file
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("InsertNewCustomerDetail_Controller", Ex.Message, path, errorlogtf);
return objModel;
}
}
}
}