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 GODATA.RoleServices; using GODATA.AuthenticationServices; using RestSharp; using Newtonsoft.Json; using GODATA.Models.UserInventory; using GODATA.Models.Ticket; using GODATA.Models.DropDownData; using GODATA.Models.Inventory; using GODATA.Models; namespace GODATA.Controllers { [GODATA.MvcApplication.SessionExpire] //public class MyBaseController : Controller //{ // protected override void OnActionExecuting(ActionExecutingContext filterContext) // { // HttpSessionStateBase session = filterContext.HttpContext.Session; // if (session.IsNewSession || Session["LoginUser"] == null) // { // filterContext.Result = Json("Session Timeout", "text/html"); // } // } //} public class UserInventoryController : Controller { #region Global Variables /// /// Global variable for CRUD repository. /// private InventoryModelRepository objInventoryRepository = null; /// /// Global variable for Ticket administration CCE portal repository. /// private TicketAdministrationRepository objTicketAdministrationRepository = null; /// /// Global variable for User management crud repository. /// private UserInventoryRepository objUserInventoryRepository = null; /// /// Global variable for Drop Down List data bind repository. /// private DropDownDataRepository objDropDownDataRepository = null; /// /// Represent object of InventoryModelRepository class /// private InventoryModelRepository objInventoryModelRepository = new InventoryModelRepository(); /// /// Represent object of LoggingUtility class /// LoggingUtility objLog = new LoggingUtility(); /// /// Represent string object contain log file path /// //string path = "~/Log/"; string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]); /// /// Represent string object contain log status /// string logtf = (ConfigurationManager.AppSettings["Log"]); /// /// Represent string object contain Error log status /// string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]); /// /// getting application name from AppSetting in web.config file /// private static string _appName = ConfigurationManager.AppSettings["ApplicationName"].ToString(); /// /// getting web api token from AppSetting in web.config file /// private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString(); /// /// getting user's utc minutes from session /// private static string _timeOffSetMinutes = null; //= System.Web.HttpContext.Current.Session["UtcMinute"].ToString(); /// /// getting login user's id /// private static string _LoginUserId = null; /// /// getting time zone id from AppSetting in web.config file /// private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString(); /// /// getting rest api url from AppSetting in web.config file /// private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString(); /// /// getting application name from AppSetting in web.config file /// //private static string _totalApplication = ConfigurationManager.AppSettings["TotalApplication"].ToString(); #endregion #region ManageVecvUserInventory /// /// Get view of vecv user inventory /// /// returns view public ActionResult ManageUserInventory() { return View(); } /// /// Get vecv and non-vecv user's list /// /// user type(vecv or non-vecv) /// return partial view for user list public ActionResult ManageUserInventory_GetUserList(string userType) { objLog.AddLogFile("ManageUserInventory_GetUserList", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); if (userType.ToLower().Trim() == "principledealer") { //Get user list and order by user name List oDealerPrincipleList = objUserInventoryRepository.GetUserList("dealer").Where(w => w.Designation.Equals("Viewer") && (w.IsDeleted.Equals(false))).OrderBy(o => o.UserName).ToList(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(oDealerPrincipleList); } //Get user list and order by user name List oUserList = objUserInventoryRepository.GetUserList(userType).Where(w => w.IsDeleted.Equals(false)).OrderBy(o => o.UserName).ToList(); if (userType.ToLower().Trim() == "dealer") { oUserList = oUserList.Where(w => w.Designation.Equals("Dealer") && (w.IsDeleted.Equals(false))).ToList(); } ViewBag.userType = userType; objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(oUserList); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_GetUserList", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Get vecv and non-vecv user's details user wise /// /// user name /// returns partial view public ActionResult ManageUserInventory_GetUserDetails(string UserName, string ObjectId) { objLog.AddLogFile("ManageUserInventory_GetUserDetails", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { UserClient oUserClient = new UserClient(); objUserInventoryRepository = new UserInventoryRepository(); List lsUserModel = oUserClient.GetUser().ToList(); //Get user details list by user name List oUserDetailsList = objUserInventoryRepository.GetUserDetail(UserName); ViewBag.ObjectId = ObjectId; objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); oUserDetailsList.ForEach(p => p.IsLocked = lsUserModel.Where(x => x.UserName == UserName).FirstOrDefault().IsLockedOut.ToString()); return PartialView(oUserDetailsList); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_GetUserDetails", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #region Get Dealer Details /// /// Get dealership details if user is Dealer /// /// Dealer Id /// return partial view public ActionResult ManageUserInventory_GetDealerUserDetails(string dealerId) { objLog.AddLogFile("ManageUserInventory_GetDealerUserDetails", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); objInventoryModelRepository = new InventoryModelRepository(); //Get dealer details list by object id ManageFleet objManageFleet = new Models.Inventory.ManageFleet(); objManageFleet = objInventoryModelRepository.GetDealerCompleteDetail(dealerId); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(objManageFleet); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_GetDealerUserDetails", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #endregion #region Add VECV user /// /// Get vecv user add form view /// /// return form view [HttpGet] public ActionResult ManageUserInventory_AddVecvUser(string input1, string input2) { objLog.AddLogFile("ManageUserInventory_AddVecvUser_Get", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { Guid UserAppId = new Guid(); string appId = Session["AuthUserAppId"].ToString(); UserAppId = new Guid(appId); objUserInventoryRepository = new UserInventoryRepository(); objTicketAdministrationRepository = new TicketAdministrationRepository(); objDropDownDataRepository = new DropDownDataRepository(); RoleClient oRoleClient = new RoleClient(); //Getting Role list //List oRoleList = oRoleClient.GetRole().OrderBy(o => o.RoleName).ToList(); List oRoleList = oRoleClient.GetAppRoleByAppId(UserAppId).OrderBy(o => o.RoleName).ToList(); //Remove roles admin and dealer from role's list var removeRoleAdmin = oRoleList.Where(w => w.RoleName.Equals("Admin")).FirstOrDefault(); var removeRoleDealer = oRoleList.Where(w => w.RoleName.Equals("Dealer")).FirstOrDefault(); var removeRoleViewer = oRoleList.Where(w => w.RoleName.Equals("Viewer")).FirstOrDefault(); var removeRoleSuperadmin1 = oRoleList.Where(w => w.RoleName.Equals("superadmin1")).FirstOrDefault(); oRoleList.Remove(removeRoleAdmin); oRoleList.Remove(removeRoleDealer); oRoleList.Remove(removeRoleViewer); oRoleList.Remove(removeRoleSuperadmin1); List oRoleNameList = new List(); foreach (RoleModel items in oRoleList) { oRoleNameList.Add(new SelectListItem { Text = items.RoleName, Value = items.RoleName.ToString() }); } ViewBag.RoleList = oRoleNameList.OrderBy(o => o.Text); //Getting Organization list user wise List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); List oOrganizationNameList = new List(); foreach (OrganizationModel items in oOrganizationList) { oOrganizationNameList.Add(new SelectListItem { Text = items.OrganizationName, Value = items.Id.ToString() }); } ViewBag.OrganizationList = oOrganizationNameList.OrderBy(o => o.Text); //Getting State list //List oStateNameList = new List(); //ViewBag.StateList = oStateNameList; List oStateList = objUserInventoryRepository.GetStateList(); List oStateNameList = new List(); foreach (StateModel items in oStateList) { oStateNameList.Add(new SelectListItem { Text = items.StateAlias, Value = items.StateId }); } ViewBag.StateList = oStateNameList.OrderBy(o => o.Text); //Getting department of eicher user List item1 = new List(); ViewBag.VehicleModelNo = item1.OrderBy(o => o.Text); //Get languages List List oLanguageList = objDropDownDataRepository.GetLanguagesList(); List oLanguageNameList = new List(); foreach (LanguageModel items in oLanguageList) { oLanguageNameList.Add(new SelectListItem { Text = items.LanguageName, Value = items.LanguageName }); } ViewBag.LanguageList = oLanguageNameList.OrderBy(o => o.Text); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_AddVecvUser_Get", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Add vecv user /// /// user model /// return json success true or false [HttpPost] public ActionResult ManageUserInventory_AddVecvUser(UserInventory model) { objLog.AddLogFile("ManageUserInventory_AddVecvUser_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); UserCreateModel UserModel = new UserCreateModel(); try { //passing user name as email id as user name must be in email format model.EmailId = model.UserName; if (model.City == "-Select-") { model.City = ""; } if (model.StateName == "-Select-") { model.StateName = ""; } objUserInventoryRepository = new UserInventoryRepository(); string vehicleTagging = null; //check if user is exist in auth engine database bool isUserExistInAuthEngine = IsUserExist(model.UserName); //if user does not exist in auth engine if (isUserExistInAuthEngine == false) { if (oUserClient.CreateUserWithRole(model.UserName, model.Password, model.EmailId, null, null, true, _appName, model.Designation)) { var userDetail = oUserClient.validateLoginDetails(model.UserName, model.Password, _appName); var resp = oUserClient.UpdateUser(userDetail.userId, model.UserName, model.EmailId, true, _appName, false); //Send request to App DB to insert new user data if (model.VehicleTaggingList != null) { foreach (var item in model.VehicleTaggingList) { vehicleTagging += item + ","; } vehicleTagging = vehicleTagging.Remove(vehicleTagging.Length - 1); model.VehicleTagging = vehicleTagging; } UserModel = objUserInventoryRepository.GetUserModel(model, "user"); objLog.AddLogFile("ManageUserInventory_AddVecvUser_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, userAuthId = model.UserName, //message = @"User registration has been done successfully" message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } else { //ModelState.AddModelError(string.Empty, "Account creation was unsuccessful. Please correct the errors and try again."); ModelState.AddModelError(string.Empty, Convert.ToString(ConfigurationManager.AppSettings["Add_User_Failed"])); } } else { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); //return Json(new { success = false, message = "User Name already exists." }); return Json(new { success = false, message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Name_Exist"]) }); } } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_AddVecvUser_post", ex.Message, path, errorlogtf); ModelState.AddModelError(string.Empty, ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } //} //// If we got this far, something failed, redisplay form objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } #endregion #endregion #region ManageDealerInventory /// /// Get non vecv user view /// /// return view public ActionResult ManageDealerInventory() { return View(); } #region Add Dealer /// /// Get add non vecv user form /// /// return form view public ActionResult ManageDealerInventory_AddDealer() { objLog.AddLogFile("ManageDealerInventory_AddDealer_get", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { Guid UserAppId = new Guid(); string appId = Session["AuthUserAppId"].ToString(); UserAppId = new Guid(appId); objUserInventoryRepository = new UserInventoryRepository(); objTicketAdministrationRepository = new TicketAdministrationRepository(); objDropDownDataRepository = new DropDownDataRepository(); RoleClient oRoleClient = new RoleClient(); //Getting Role list //List oRoleList = oRoleClient.GetRole().ToList(); List oRoleList = oRoleClient.GetAppRoleByAppId(UserAppId).OrderBy(o => o.RoleName).ToList(); //Remove roles admin and dealer from role's list var removeRoleAdmin = oRoleList.Where(w => w.RoleName.Equals("Admin")).FirstOrDefault(); var removeRoleDealer = oRoleList.Where(w => w.RoleName.Equals("Dealer")).FirstOrDefault(); var removeRoleViewer = oRoleList.Where(w => w.RoleName.Equals("Viewer")).FirstOrDefault(); var removeRoleSuperadmin1 = oRoleList.Where(w => w.RoleName.Equals("superadmin1")).FirstOrDefault(); oRoleList.Remove(removeRoleAdmin); oRoleList.Remove(removeRoleDealer); oRoleList.Remove(removeRoleViewer); oRoleList.Remove(removeRoleSuperadmin1); List oRoleNameList = new List(); foreach (RoleModel items in oRoleList) { oRoleNameList.Add(new SelectListItem { Text = items.RoleName, Value = items.RoleName.ToString() }); } ViewBag.RoleList = oRoleNameList.OrderBy(o => o.Text); //Getting Organization list user wise List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); List oOrganizationNameList = new List(); foreach (OrganizationModel items in oOrganizationList) { oOrganizationNameList.Add(new SelectListItem { Text = items.OrganizationName, Value = items.Id.ToString() }); } ViewBag.OrganizationList = oOrganizationNameList.OrderBy(o => o.Text); //Getting State list List oStateList = objUserInventoryRepository.GetStateList(); List oStateNameList = new List(); foreach (StateModel items in oStateList) { oStateNameList.Add(new SelectListItem { Text = items.StateAlias, Value = items.StateId }); } ViewBag.StateList = oStateNameList.OrderBy(o => o.Text); //Getting non-vecv users list List oNonUserDealerList = objUserInventoryRepository.GetNonUserDealersList(); List item11 = new List(); foreach (DealerModel items in oNonUserDealerList) { item11.Add(new SelectListItem { Text = items.sDlrNamewithDealerId, Value = items.DealerId }); } ViewBag.NonUserDealerList = item11.OrderBy(o => o.Text); //Get languages List List oLanguageList = objDropDownDataRepository.GetLanguagesList(); List oLanguageNameList = new List(); foreach (LanguageModel items in oLanguageList) { oLanguageNameList.Add(new SelectListItem { Text = items.LanguageName, Value = items.LanguageName }); } ViewBag.LanguageList = oLanguageNameList.OrderBy(o => o.Text); objInventoryRepository = new InventoryModelRepository(); _LoginUserId = Session["UserName"].ToString(); //Getting non-vecv users list List oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList(); List item12 = new List(); foreach (ManageFleet items in oDealerList) { item12.Add(new SelectListItem { Text = items.sDlrNamewithDealerId, Value = items.DealerId }); } ViewBag.DealerList = item12.OrderBy(o => o.Text); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_IsUserExistInAuth", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Add non-vecv user /// /// user model /// return json success true or false [HttpPost] public ActionResult ManageDealerInventory_AddDealer(UserInventory model) { objLog.AddLogFile("ManageDealerInventory_AddDealer_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); objUserInventoryRepository = new UserInventoryRepository(); if (model != null) { UserClient oUserClient = new UserClient(); UserCreateModel UserModel = new UserCreateModel(); try { //passing user name as email id as user name must be in email format model.EmailId = model.UserName; //check if user is exist in auth engine database bool isUserExistInAuthEngine = IsUserExist(model.UserName); //#region add dealer user in vota web app too in auth engine ////total application associated with same auth engine //bool[] isUserCreationSuccess = new bool[Convert.ToInt32(_totalApplication)]; //#endregion if (isUserExistInAuthEngine == false) { //#region add dealer user for vota web app too in auth engine ////creating user in more than one application in same auth engine //for (var count = 0; count < Convert.ToInt32(_totalApplication); count++) //{ // var applicationName = ConfigurationManager.AppSettings["ApplicationName" + (count + 1)]; // //store user creation result in an array for each application // isUserCreationSuccess[count] = oUserClient.CreateUserWithRole(model.UserName, model.Password, model.EmailId, null, null, true, ConfigurationManager.AppSettings["ApplicationName" + (count + 1)], model.Designation); // if (isUserCreationSuccess[count]) // { // var userDetail = oUserClient.validateLoginDetails(model.UserName, model.Password, ConfigurationManager.AppSettings["ApplicationName" + (count + 1)]); // var resp = oUserClient.UpdateUser(userDetail.userId, model.UserName, model.EmailId, true, ConfigurationManager.AppSettings["ApplicationName" + (count + 1)], false); // #region add vota dealer in vota web app database user from eos web app // //if (applicationName == ConfigurationManager.AppSettings["ApplicationName2"]) // //{ // // UserModel = objUserInventoryRepository.GetVotaUserModel(model, "dealer"); // // objLog.AddLogFile("ManageDealerInventory_AddVotaDealer_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); // //} // #endregion // } //} // #endregion if (oUserClient.CreateUserWithRole(model.UserName, model.Password, model.EmailId, null, null, true, _appName, model.Designation)) { var userDetail = oUserClient.validateLoginDetails(model.UserName, model.Password, _appName); var resp = oUserClient.UpdateUser(userDetail.userId, model.UserName, model.EmailId, true, _appName, false); //#region add dealer user for vota web app too in auth engine //if (isUserCreationSuccess[0]) //{ //#endregion //Send request to App DB to insert new user data UserModel = objUserInventoryRepository.GetUserModel(model, "dealer"); objLog.AddLogFile("ManageDealerInventory_AddDealer_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, userAuthId = model.UserName, //message = @"User registration has been done successfully" message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } else { //ModelState.AddModelError(string.Empty, "Account creation was unsuccessful. Please correct the errors and try again."); ModelState.AddModelError(string.Empty, Convert.ToString(ConfigurationManager.AppSettings["Add_User_Failed"])); } } else { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); //return Json(new { success = false, message = "User Name already exists." }); return Json(new { success = false, message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Name_Exist"]) }); } } catch (Exception ex) { objLog.ErrorLogFile("ManageDealerInventory_GetOrganizationDealerWise", ex.Message, path, errorlogtf); ModelState.AddModelError(string.Empty, ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } } //// If we got this far, something failed, redisplay form objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return View(); } #endregion #endregion #region Common functions for Manage eicher/non-eicher users /// /// Get city list based on state id /// /// State id /// returns city list public ActionResult showCityStateWise(int stateVal) { objLog.AddLogFile("ManageUserInventory_showCityStateWise", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); if (stateVal != 0) { //Get city list List oCityList = objUserInventoryRepository.GetCityList(stateVal); List oCityNameList = new List(); foreach (CityModel items in oCityList) { if (items.CityName != null) { oCityNameList.Add(new SelectListItem { Text = items.CityName, Value = items.CityName.ToString() }); } } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, list = oCityNameList.OrderBy(o => o.Text) }, JsonRequestBehavior.AllowGet); } else { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_showCityStateWise", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Get region name for autocomplete /// /// returns region name list public JsonResult GetRegionNameList() { objLog.AddLogFile("ManageUserInventory_GetRegionNameList", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); //Get region list List regionModel = objUserInventoryRepository.GetRegionModel().OrderBy(o => o.RegionName).ToList(); regionModel.RemoveAt(0); List regionList = new List(); foreach (var item in regionModel) { regionList.Add(item.RegionName); } //Convert region List to Array to display it in autocomplete text box string[] regionListName = regionList.ToArray(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { regionNameList = regionListName }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_GetRegionNameList", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// check user if exist already /// /// user name /// return true if exist otherwise false public ActionResult CheckUserIsExist(string UserName) { objLog.AddLogFile("ManageUserInventory_CheckIsUserExist", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); UserCreateModel oUserDetailsModel = objUserInventoryRepository.GetUserOrganizationDetails(UserName); objLog.AddLogFile("ManageUserInventory_CheckIsUserExist", oUserDetailsModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (oUserDetailsModel.Status != "0") { return Json(new { result = false }, JsonRequestBehavior.AllowGet); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { result = true }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_CheckIsUserExist", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// check email id if exist already /// /// user's email id /// public ActionResult CheckEmailIsExist(string EmailId) { objLog.AddLogFile("ManageUserInventory_CheckEmailIsExist", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); UserCreateModel oUserDetailsModel = objUserInventoryRepository.GetUserOrganizationDetails(EmailId); objLog.AddLogFile("ManageUserInventory_CheckEmailIsExist", oUserDetailsModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (oUserDetailsModel.Status == "1") { return Json(new { result = false }, JsonRequestBehavior.AllowGet); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { result = true }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_CheckEmailIsExist", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// check if user name is exist or not in auth engine db /// /// input user name string /// return true or false [HttpGet] public bool IsUserExist(string userName) { objLog.AddLogFile("ManageUserInventory_IsUserExistInAuth", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); bool res = false; try { var result = oUserClient.GetUser(); foreach (var item in result) { if (item.UserName.ToLower() == userName.ToLower()) { res = true; } } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return res; } catch (Exception ex) { oUserClient.Close(); objLog.ErrorLogFile("ManageUserInventory_IsUserExistInAuth", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw new Exception(ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } } /// /// Get organization name non-vecv user name wise /// /// non-vecv user(dealers) id /// return json of organization name and id public ActionResult GetOrganizationDealerWise(string dealerId) { objLog.AddLogFile("ManageDealerInventory_GetOrganizationDealerWise", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); if (dealerId != null) { //Getting list of non-vecv user(dealers) list List oDealerList = objUserInventoryRepository.GetNonUserDealersList(); var OrganizationListDealerWise = oDealerList.Where(w => w.DealerId.Equals(dealerId)); var organizationId = OrganizationListDealerWise.Select(s => s.OrganizationId).First(); var dealerState = OrganizationListDealerWise.Select(s => s.DealerState).First(); var dealerCity = OrganizationListDealerWise.Select(s => s.DealerCity).First(); //Getting list of organizations List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); //Getting list of selected dealer's organization details and organization name var organizationNameWiseList = oOrganizationList.Where(w => w.Id.Equals(organizationId)).ToList(); var organizationName = organizationNameWiseList.Select(s => s.OrganizationName).ToList(); var selectedOrganizationId = organizationNameWiseList.Select(s => s.Id).ToList(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); //return Json(new { success = true, organizationName = organizationName, organizationId = selectedOrganizationId }, JsonRequestBehavior.AllowGet); return Json(new { success = true, listOrganization = organizationNameWiseList, organizationName = organizationName, organizationId = selectedOrganizationId, state = dealerState, city = dealerCity }, JsonRequestBehavior.AllowGet); } else { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { objLog.ErrorLogFile("ManageDealerInventory_GetOrganizationDealerWise", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #endregion #region Manage Principal Dealership CRUD /// /// Get Principle Dealer view /// /// return view public ActionResult ManagePrincipleDealerInventory() { return View(); } #region add principal dealer /// /// Get add Principle Dealer user form /// /// return form view [HttpGet] public ActionResult ManagePrincipleDealerInventory_AddPrincipleDealer() { objLog.AddLogFile("ManagePrincipleDealerInventory_AddPrincipleDealer_get", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); objTicketAdministrationRepository = new TicketAdministrationRepository(); objDropDownDataRepository = new DropDownDataRepository(); RoleClient oRoleClient = new RoleClient(); //Getting Organization list user wise List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); List oOrganizationNameList = new List(); foreach (OrganizationModel items in oOrganizationList) { oOrganizationNameList.Add(new SelectListItem { Text = items.OrganizationName, Value = items.Id.ToString() }); } ViewBag.OrganizationList = oOrganizationNameList.OrderBy(o => o.Text); //Getting State list List oStateList = objUserInventoryRepository.GetStateList(); List oStateNameList = new List(); foreach (StateModel items in oStateList) { oStateNameList.Add(new SelectListItem { Text = items.StateAlias, Value = items.StateId }); } ViewBag.StateList = oStateNameList.OrderBy(o => o.Text); objInventoryRepository = new InventoryModelRepository(); _LoginUserId = Session["UserName"].ToString(); //Getting non-vecv users list List oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList(); List item12 = new List(); foreach (ManageFleet items in oDealerList) { item12.Add(new SelectListItem { Text = items.sDlrNamewithDealerId, Value = items.DealerId }); } ViewBag.DealerList = item12.OrderBy(o => o.Text); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } catch (Exception ex) { objLog.ErrorLogFile("ManagePrincipleDealerInventory_AddPrincipleDealer_get", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Add Principle Dealer user /// /// user model /// return json success true or false [HttpPost] public ActionResult ManagePrincipleDealerInventory_AddPrincipleDealer(UserInventory model) { objLog.AddLogFile("ManagePrincipleDealerInventory_AddPrincipleDealer_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); DealerPrincipleCreateModel UserModel = new DealerPrincipleCreateModel(); try { //passing user name as email id as user name must be in email format model.Designation = "Viewer"; model.IsPrincipleDealer = true; model.EmailId = model.UserName; if (model.City == "-Select-") { model.City = ""; } if (model.StateName == "-Select-") { model.StateName = ""; } objUserInventoryRepository = new UserInventoryRepository(); string DealerChildList = null; //check if user is exist in auth engine database bool isUserExistInAuthEngine = IsUserExist(model.UserName); //if user does not exist in auth engine if (isUserExistInAuthEngine == false) { if (oUserClient.CreateUserWithRole(model.UserName, model.Password, model.EmailId, null, null, true, _appName, model.Designation)) { var userDetail = oUserClient.validateLoginDetails(model.UserName, model.Password, _appName); var resp = oUserClient.UpdateUser(userDetail.userId, model.UserName, model.EmailId, true, _appName, false); //Send request to App DB to insert new user data if (model.ChildDealerList != null) { foreach (var item in model.ChildDealerList) { DealerChildList += item + ","; } DealerChildList = DealerChildList.Remove(DealerChildList.Length - 1); model.DealerChildList = DealerChildList; } UserModel = objUserInventoryRepository.GetDealerPrincipleModel(model, "principleDealer", "insert"); objLog.AddLogFile("ManageUserInventory_AddVecvUser_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, userAuthId = model.UserName, //message = @"User registration has been done successfully" message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } else { //ModelState.AddModelError(string.Empty, "Account creation was unsuccessful. Please correct the errors and try again."); ModelState.AddModelError(string.Empty, Convert.ToString(ConfigurationManager.AppSettings["Add_User_Failed"])); } } else { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); //return Json(new { success = false, message = "User Name already exists." }); return Json(new { success = false, message = Convert.ToString(ConfigurationManager.AppSettings["Add_User_Name_Exist"]) }); } } catch (Exception ex) { objLog.ErrorLogFile("ManagePrincipleDealerInventory_AddPrincipleDealer_post", ex.Message, path, errorlogtf); ModelState.AddModelError(string.Empty, ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } //// If we got this far, something failed, redisplay form objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } #endregion #region Get Details of dealer Principal /// /// Get view to show Dealer Principal Details /// /// Dealer Principal's Id /// return partial view public ActionResult ManageUserInventory_GetDealerPrincipalDetails(string dealerPrincipalId) { objLog.AddLogFile("ManageUserInventory_GetDealerPrincipalDetails", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); objInventoryModelRepository = new InventoryModelRepository(); string childDealers = ""; ViewBag.childDealers = ""; //Get principal dealer details by object id DealerPrincipleCreateModel oDealerPrincipalDetails = new DealerPrincipleCreateModel(); oDealerPrincipalDetails = objUserInventoryRepository.GetDealerPrincipalCompleteDetail(dealerPrincipalId, "getprincipaldealerdetails"); //bind dealer principal details in viewbag ViewBag.DealerPrincipalDetails = oDealerPrincipalDetails.DealerChildPrincipalList.ToList(); //Get principal dealer child details by object id DealerPrincipleCreateModel oChildDealerPrincipalDetails = new DealerPrincipleCreateModel(); oChildDealerPrincipalDetails = objUserInventoryRepository.GetDealerPrincipalCompleteDetail(dealerPrincipalId, "getchilddealers"); //remove principal dealer from child dealer list var removeDealerFromChildList = oChildDealerPrincipalDetails.DealerChildPrincipalList.Where(w => w.DealerId.Equals(dealerPrincipalId)).FirstOrDefault(); oChildDealerPrincipalDetails.DealerChildPrincipalList.Remove(removeDealerFromChildList); if (oChildDealerPrincipalDetails.DealerChildPrincipalList.Count > 0) { foreach (var item in oChildDealerPrincipalDetails.DealerChildPrincipalList) { childDealers += item.DealerId + " "; } ViewBag.childDealers = childDealers.Trim().Replace(" ", ","); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(oChildDealerPrincipalDetails.DealerChildPrincipalList); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_GetDealerUserDetails", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #endregion #region edit dealer principle /// /// Get add Principle Dealer user form /// /// return form view [HttpGet] public ActionResult ManagePrincipleDealerInventory_EditPrincipleDealer(string UserName, string ObjectId) { objLog.AddLogFile("ManagePrincipleDealerInventory_EditPrincipleDealer_get", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objUserInventoryRepository = new UserInventoryRepository(); objTicketAdministrationRepository = new TicketAdministrationRepository(); objDropDownDataRepository = new DropDownDataRepository(); int stateVal = 0; int regionVal = 0; UserInventory objUserInventory = new UserInventory(); //Get user details list by user name List oUserDetailsList = objUserInventoryRepository.GetUserDetail(UserName); foreach (var item in oUserDetailsList) { objUserInventory.UserId = item.UserId; objUserInventory.UserName = item.UserName; objUserInventory.Designation = item.Designation; objUserInventory.OrganizationId = item.OrganizationId.ToString(); objUserInventory.Language = item.Language; objUserInventory.State = item.StateId; objUserInventory.City = item.City; objUserInventory.ObjectId = ObjectId; stateVal = Convert.ToInt32(item.StateId); regionVal = item.OrganizationId; } //Get principal dealer details by object id DealerPrincipleCreateModel oDealerPrincipalDetails = new DealerPrincipleCreateModel(); oDealerPrincipalDetails = objUserInventoryRepository.GetDealerPrincipalCompleteDetail(ObjectId, "getprincipaldealerdetails"); objUserInventory.PrincipleDealerContactNo = oDealerPrincipalDetails.DealerChildPrincipalList.ToList().Select(s => s.DealerContact1).ToArray().ElementAt(0); objUserInventory.FirstName = oDealerPrincipalDetails.DealerChildPrincipalList.ToList().Select(s => s.DealerName).ToArray().ElementAt(0); //Get principal dealer child details by object id DealerPrincipleCreateModel oChildDealerPrincipalDetails = new DealerPrincipleCreateModel(); oChildDealerPrincipalDetails = objUserInventoryRepository.GetDealerPrincipalCompleteDetail(ObjectId, "getchilddealers"); //remove principal dealer from child dealer list var removeDealerFromChildList = oChildDealerPrincipalDetails.DealerChildPrincipalList.Where(w => w.DealerId.Equals(ObjectId)).FirstOrDefault(); oChildDealerPrincipalDetails.DealerChildPrincipalList.Remove(removeDealerFromChildList); //bind dealer principal details in viewbag var ChildDealerPrincipal = oChildDealerPrincipalDetails.DealerChildPrincipalList.ToList(); ViewBag.ChildDealerList = (ChildDealerPrincipal != null && ChildDealerPrincipal.Count > 0) ? ChildDealerPrincipal.Select(s => s.DealerId).ToArray() : null; //Getting Organization list user wise List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); List oOrganizationNameList = new List(); foreach (OrganizationModel items in oOrganizationList) { oOrganizationNameList.Add(new SelectListItem { Text = items.OrganizationName, Value = items.Id.ToString() }); } ViewBag.OrganizationList = oOrganizationNameList.OrderBy(o => o.Text); objTicketAdministrationRepository = new TicketAdministrationRepository(); //Getting State List List oStateList = objTicketAdministrationRepository.GetStateListRegionWise(regionVal); List oStateNameList = new List(); foreach (StateModel items in oStateList) { oStateNameList.Add(new SelectListItem { Text = items.StateAlias, Value = items.StateId }); } ViewBag.StateList = oStateNameList.OrderBy(o => o.Text); //Get city list List oCityList = objUserInventoryRepository.GetCityList(stateVal); List oCityNameList = new List(); foreach (CityModel items in oCityList) { if (items.CityName != null) { oCityNameList.Add(new SelectListItem { Text = items.CityName, Value = items.CityName.ToString() }); } } ViewBag.CityList = oCityNameList.OrderBy(o => o.Text); objInventoryRepository = new InventoryModelRepository(); _LoginUserId = Session["UserName"].ToString(); //Getting non-vecv users list List oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList(); List item12 = new List(); foreach (ManageFleet items in oDealerList) { item12.Add(new SelectListItem { Text = items.sDlrNamewithDealerId, Value = items.DealerId }); } ViewBag.DealerList = item12.OrderBy(o => o.Text); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(objUserInventory); } catch (Exception ex) { objLog.ErrorLogFile("ManagePrincipleDealerInventory_AddPrincipleDealer_get", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Add vecv user /// /// user model /// return json success true or false [HttpPost] public ActionResult ManagePrincipleDealerInventory_EditPrincipleDealer(UserInventory model) { objLog.AddLogFile("ManagePrincipleDealerInventory_EditPrincipleDealer_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); DealerPrincipleCreateModel UserModel = new DealerPrincipleCreateModel(); try { string action = ""; //passing user name as email id as user name must be in email format model.Designation = "Viewer"; model.IsPrincipleDealer = true; model.EmailId = model.UserName; if (model.City == "-Select-") { model.City = ""; } if (model.StateName == "-Select-") { model.StateName = ""; } objUserInventoryRepository = new UserInventoryRepository(); string DealerChildList = null; if (model.IsDealerDeleted == true) { action = "delete"; } else { model.IsDealerDeleted = false; action = "update"; //Send request to App DB to insert new user data if (model.ChildDealerList != null) { foreach (var item in model.ChildDealerList) { DealerChildList += item + ","; } DealerChildList = DealerChildList.Remove(DealerChildList.Length - 1); model.DealerChildList = DealerChildList; } } UserModel = objUserInventoryRepository.GetDealerPrincipleModel(model, "principleDealer", action); objLog.AddLogFile("ManagePrincipleDealerInventory_EditPrincipleDealer_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, userAuthId = model.UserName, //message = @"User registration has been done successfully" message = Convert.ToString(ConfigurationManager.AppSettings["Edit_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } catch (Exception ex) { objLog.ErrorLogFile("ManagePrincipleDealerInventory_EditPrincipleDealer_post", ex.Message, path, errorlogtf); ModelState.AddModelError(string.Empty, ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } //} //// If we got this far, something failed, redisplay form objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } #endregion #region delete Dealer principal #endregion #endregion #region CRUD User [HttpGet] public ActionResult ManageUserInventory_EditVecvUser(string UserName, string ObjectId) { objLog.AddLogFile("ManageUserInventory_AddVecvUser_Edit", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { Guid UserAppId = new Guid(); string appId = Session["AuthUserAppId"].ToString(); int stateVal = 0; int regionVal = 0; UserAppId = new Guid(appId); objUserInventoryRepository = new UserInventoryRepository(); objTicketAdministrationRepository = new TicketAdministrationRepository(); objDropDownDataRepository = new DropDownDataRepository(); RoleClient oRoleClient = new RoleClient(); //Getting Role list //List oRoleList = oRoleClient.GetRole().OrderBy(o => o.RoleName).ToList(); List oRoleList = oRoleClient.GetAppRoleByAppId(UserAppId).OrderBy(o => o.RoleName).ToList(); //Remove roles admin and dealer from role's list var removeRoleAdmin = oRoleList.Where(w => w.RoleName.Equals("Admin")).FirstOrDefault(); var removeRoleDealer = oRoleList.Where(w => w.RoleName.Equals("Dealer")).FirstOrDefault(); var removeRoleViewer = oRoleList.Where(w => w.RoleName.Equals("Viewer")).FirstOrDefault(); var removeRoleSuperadmin1 = oRoleList.Where(w => w.RoleName.Equals("superadmin1")).FirstOrDefault(); oRoleList.Remove(removeRoleAdmin); oRoleList.Remove(removeRoleDealer); oRoleList.Remove(removeRoleViewer); oRoleList.Remove(removeRoleSuperadmin1); UserInventory objUserInventory = new UserInventory(); //Get user details list by user name List oUserDetailsList = objUserInventoryRepository.GetUserDetail(UserName); foreach (var item in oUserDetailsList) { objUserInventory.UserId = item.UserId; objUserInventory.UserName = item.UserName; objUserInventory.FirstName = item.FirstName; objUserInventory.Designation = item.Designation; objUserInventory.OrganizationId = item.OrganizationId.ToString(); objUserInventory.Language = item.Language; objUserInventory.State = item.StateId; objUserInventory.City = item.City; objUserInventory.VehicleTagging = item.VehicleTagging; stateVal = Convert.ToInt32(item.StateId); regionVal = item.OrganizationId; } ViewBag.VehicleTags = (objUserInventory.VehicleTagging != null && objUserInventory.VehicleTagging != "") ? objUserInventory.VehicleTagging.Split(',') : null; List oRoleNameList = new List(); foreach (RoleModel items in oRoleList) { oRoleNameList.Add(new SelectListItem { Text = items.RoleName, Value = items.RoleName.ToString() }); } ViewBag.RoleList = oRoleNameList.OrderBy(o => o.Text); //Getting Organization list user wise List oOrganizationList = objUserInventoryRepository.GetOrganizationList(); List oOrganizationNameList = new List(); foreach (OrganizationModel items in oOrganizationList) { oOrganizationNameList.Add(new SelectListItem { Text = items.OrganizationName, Value = items.Id.ToString() }); } ViewBag.OrganizationList = oOrganizationNameList.OrderBy(o => o.Text); objTicketAdministrationRepository = new TicketAdministrationRepository(); //Getting State List List oStateList = objTicketAdministrationRepository.GetStateListRegionWise(regionVal); List oStateNameList = new List(); foreach (StateModel items in oStateList) { oStateNameList.Add(new SelectListItem { Text = items.StateAlias, Value = items.StateId }); } ViewBag.StateList = oStateNameList.OrderBy(o => o.Text); //Get city list List oCityList = objUserInventoryRepository.GetCityList(stateVal); List oCityNameList = new List(); foreach (CityModel items in oCityList) { if (items.CityName != null) { oCityNameList.Add(new SelectListItem { Text = items.CityName, Value = items.CityName.ToString() }); } } ViewBag.CityList = oCityNameList.OrderBy(o => o.Text); //Getting department of eicher user List item1 = new List(); ViewBag.VehicleModelNo = item1.OrderBy(o => o.Text); //Get languages List List oLanguageList = objDropDownDataRepository.GetLanguagesList(); List oLanguageNameList = new List(); foreach (LanguageModel items in oLanguageList) { oLanguageNameList.Add(new SelectListItem { Text = items.LanguageName, Value = items.LanguageName }); } ViewBag.LanguageList = oLanguageNameList.OrderBy(o => o.Text); ViewBag.ObjectId = ObjectId; objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(objUserInventory); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_AddVecvUser_Get", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Add vecv user /// /// user model /// return json success true or false [HttpPost] public ActionResult ManageUserInventory_EditVecvUser(UserInventory model) { objLog.AddLogFile("ManageUserInventory_EditVecvUser_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); UserCreateModel UserModel = new UserCreateModel(); try { //passing user name as email id as user name must be in email format model.EmailId = model.UserName; if (model.City == "-Select-") { model.City = ""; } if (model.StateName == "-Select-") { model.StateName = ""; } objUserInventoryRepository = new UserInventoryRepository(); string vehicleTagging = null; //Send request to App DB to insert new user data if (model.VehicleTaggingList != null) { foreach (var item in model.VehicleTaggingList) { vehicleTagging += item + ","; } vehicleTagging = vehicleTagging.Remove(vehicleTagging.Length - 1); model.VehicleTagging = vehicleTagging; } UserModel = objUserInventoryRepository.EditDeleteUserModel(model, "user"); objLog.AddLogFile("ManageUserInventory_EditVecvUser_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, userAuthId = model.UserName, //message = @"User registration has been done successfully" message = Convert.ToString(ConfigurationManager.AppSettings["Edit_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } catch (Exception ex) { objLog.ErrorLogFile("ManageUserInventory_EditVecvUser_post", ex.Message, path, errorlogtf); ModelState.AddModelError(string.Empty, ex.Message); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } //} //// If we got this far, something failed, redisplay form objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return PartialView(); } #endregion #region Dealer user CRUD /// /// Get add non vecv user form /// /// return form view public JsonResult ManageDealerInventory_DeleteDealer(UserInventory model) { objLog.AddLogFile("ManageDealerInventory_DeleteDealer_post", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); UserCreateModel UserModel = new UserCreateModel(); try { //passing user name as email id as user name must be in email format model.EmailId = model.UserName; objUserInventoryRepository = new UserInventoryRepository(); UserModel = objUserInventoryRepository.EditDeleteUserModel(model, "dealer"); objLog.AddLogFile("ManageDealerInventory_DeleteDealer_post", UserModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (UserModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserModel[] arrUserModel = oUserClient.GetApplicationUser(new Guid(ConfigurationManager.AppSettings["ApplicationID"].ToString())); UserModel objUserModel = arrUserModel.Where(p => p.ApplicationId == new Guid(ConfigurationManager.AppSettings["ApplicationID"].ToString()) && p.UserName == model.UserName).SingleOrDefault(); oUserClient.DeleteUser(objUserModel.UserId, new Guid(ConfigurationManager.AppSettings["ApplicationID"].ToString())); return Json(new { success = true, userAuthId = model.UserName, message = Convert.ToString(ConfigurationManager.AppSettings["Edit_User_Success"]) }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false, message = "" }); } catch (Exception ex) { objLog.ErrorLogFile("ManageDealerInventory_DeleteDealer_post", ex.Message, path, errorlogtf); return Json(new { success = false, message = "" }); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } } #endregion #region Non Eicher user - Reset Password /// /// Reset the pwd of non vecv user form /// /// return form view [HttpPost] public JsonResult ManageDealerInventory_UnlockUser(ResetPasswordModel model) { objLog.AddLogFile("ManageDealerInventory_UnlockUser", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); try { objUserInventoryRepository = new UserInventoryRepository(); List lsUserModel = oUserClient.GetUser().ToList(); //Get user details list by user name List oUserDetailsList = objUserInventoryRepository.GetUserDetail(model.UserName); model.UserName = model.UserName.Replace(@"\r\n", ""); Guid objuserguid = lsUserModel.Where(p => p.Email.Trim() == model.UserName.Trim() && p.ApplicationName == _appName).FirstOrDefault().UserId; bool isUserUnlock = oUserClient.UnlockUser(objuserguid); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (isUserUnlock == true) { return Json(new { success = true, userName = model.UserName.Trim() }); } else { return Json(new { success = false, userName = model.UserName.Trim() }); } } catch (Exception ex) { objLog.ErrorLogFile("ManageDealerInventory_UnlockUser", ex.Message, path, errorlogtf); return Json(new { success = false }); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } } #endregion #region Non Eicher user - Reset Password /// /// Reset the pwd of non vecv user form /// /// return form view [HttpPost] public JsonResult ManageDealerInventory_ResetDealerPwd(ResetPasswordModel model) { objLog.AddLogFile("ManageDealerInventory_ResetDealerPwd", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); UserClient oUserClient = new UserClient(); try { string resetPassword = oUserClient.ForgotPassword(model.UserName); bool isPwdChange = oUserClient.ChangePassword(model.UserName, resetPassword, model.ResetNewPassword); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (isPwdChange == true) { return Json(new { success = true }); } else { return Json(new { success = false }); } } catch (Exception ex) { objLog.ErrorLogFile("ManageDealerInventory_ResetDealerPwd", ex.Message, path, errorlogtf); return Json(new { success = false }); } finally { if (oUserClient.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted) { oUserClient.Close(); } } } #endregion } }