namespace VECV_WebApi.Controllers.User { #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 VECV_WebApi.Models.User; #endregion /// /// This controller contain apis releted to user /// public class UserController : 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 User model object available to this class /// UserModel objUserModel; /// /// making User Repository object available to this class /// UserRepository objUserRepository; /// /// making the Database connection string available to this class /// private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString(); #endregion #region APIs /// /// To get user detail, user name wise /// /// user info /// status and data public UserModel Post([FromBody]UserModel model) { objUserModel = new UserModel(); try { objUserRepository = new UserRepository(_connStr); objUserModel = objUserRepository.GetUserDetailUserNameWise(model); return objUserModel; } catch (Exception Ex) { // write error log into file objUserModel.Status = "0"; objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message; objLog.ErrorLogFile("GetUserDetailUserNameWise_Controller", Ex.Message, path, errorlogtf); return objUserModel; } } /// /// To create new user /// /// extra param to identify the api /// user details /// status 0 or 1 public UserModel Post([FromUri]string NewUser, [FromBody]UserModel model) { objUserModel = new UserModel(); try { objUserRepository = new UserRepository(_connStr); objUserModel = objUserRepository.InsertNewUserDetail(model); return objUserModel; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("InsertNewUserDetail_Controller", Ex.Message, path, errorlogtf); objUserModel.Status = "0"; objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message; return objUserModel; } } /// /// To create new user /// /// extra param to identify the api /// user details /// status 0 or 1 public UserModel Post([FromUri]string User, [FromUri]string UpdateDeleteUser, [FromBody]UserModel model) { objUserModel = new UserModel(); try { objUserRepository = new UserRepository(_connStr); objUserModel = objUserRepository.UpdateOrDeleteUserDetail(model); return objUserModel; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("UpdateOrDeleteUserDetail_Controller", Ex.Message, path, errorlogtf); objUserModel.Status = "0"; objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message; return objUserModel; } } /// /// To get details of dealer, user id wise /// /// extra param to identify the api /// extra param to identify the api /// dealer info /// status and data public List post([FromUri]string Dealer, [FromUri]string NonUser, [FromBody]DealerModel model) { try { List objList = new List(); objUserRepository = new UserRepository(_connStr); objList = objUserRepository.GetNonUserDealer(model); return objList; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("GetNonUserDealer_Controller", Ex.Message, path, errorlogtf); throw Ex; } } /// /// To get details of user/dealer, user id wise /// /// extra param to identify the api /// extra param to identify the api /// to diffrentiate between normal user and dealer /// user info /// status and data public List Post([FromUri]string User, [FromUri]string Dealer, [FromUri]string UserType, [FromBody]UserModel model) { // write data log into file try { List objList = new List(); objUserRepository = new UserRepository(_connStr); if (UserType.ToLower() == "user") { objList = objUserRepository.GetUserListUserIdWise(model); } else { objList = objUserRepository.GetDealerListUserIdWise(model); } return objList; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("GetUserListUserIdWise or GetDealerListUserIdWise_Controller", Ex.Message, path, errorlogtf); throw Ex; } } #endregion } }