EOS/Controllers/UserInventoryController.cs
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

1710 lines
80 KiB
C#

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
/// <summary>
/// Global variable for CRUD repository.
/// </summary>
private InventoryModelRepository objInventoryRepository = null;
/// <summary>
/// Global variable for Ticket administration CCE portal repository.
/// </summary>
private TicketAdministrationRepository objTicketAdministrationRepository = null;
/// <summary>
/// Global variable for User management crud repository.
/// </summary>
private UserInventoryRepository objUserInventoryRepository = null;
/// <summary>
/// Global variable for Drop Down List data bind repository.
/// </summary>
private DropDownDataRepository objDropDownDataRepository = null;
/// <summary>
/// Represent object of InventoryModelRepository class
/// </summary>
private InventoryModelRepository objInventoryModelRepository = new InventoryModelRepository();
/// <summary>
/// Represent object of LoggingUtility class
/// </summary>
LoggingUtility objLog = new LoggingUtility();
/// <summary>
/// Represent string object contain log file path
/// </summary>
//string path = "~/Log/";
string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
/// <summary>
/// Represent string object contain log status
/// </summary>
string logtf = (ConfigurationManager.AppSettings["Log"]);
/// <summary>
/// Represent string object contain Error log status
/// </summary>
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
/// <summary>
/// getting application name from AppSetting in web.config file
/// </summary>
private static string _appName = ConfigurationManager.AppSettings["ApplicationName"].ToString();
/// <summary>
/// getting web api token from AppSetting in web.config file
/// </summary>
private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString();
/// <summary>
/// getting user's utc minutes from session
/// </summary>
private static string _timeOffSetMinutes = null;
//= System.Web.HttpContext.Current.Session["UtcMinute"].ToString();
/// <summary>
/// getting login user's id
/// </summary>
private static string _LoginUserId = null;
/// <summary>
/// getting time zone id from AppSetting in web.config file
/// </summary>
private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString();
/// <summary>
/// getting rest api url from AppSetting in web.config file
/// </summary>
private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString();
/// <summary>
/// getting application name from AppSetting in web.config file
/// </summary>
//private static string _totalApplication = ConfigurationManager.AppSettings["TotalApplication"].ToString();
#endregion
#region ManageVecvUserInventory
/// <summary>
/// Get view of vecv user inventory
/// </summary>
/// <returns>returns view</returns>
public ActionResult ManageUserInventory()
{
return View();
}
/// <summary>
/// Get vecv and non-vecv user's list
/// </summary>
/// <param name="userType">user type(vecv or non-vecv)</param>
/// <returns>return partial view for user list</returns>
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<UserCreateModel> 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<UserCreateModel> 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;
}
}
/// <summary>
/// Get vecv and non-vecv user's details user wise
/// </summary>
/// <param name="UserName">user name</param>
/// <returns>returns partial view</returns>
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<UserModel> lsUserModel = oUserClient.GetUser().ToList();
//Get user details list by user name
List<UserCreateModel> 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
/// <summary>
/// Get dealership details if user is Dealer
/// </summary>
/// <param name="dealerId">Dealer Id</param>
/// <returns>return partial view</returns>
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
/// <summary>
/// Get vecv user add form view
/// </summary>
/// <returns>return form view</returns>
[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<RoleModel> oRoleList = oRoleClient.GetRole().OrderBy(o => o.RoleName).ToList();
List<RoleModel> 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<SelectListItem> oRoleNameList = new List<SelectListItem>();
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<OrganizationModel> oOrganizationList = objUserInventoryRepository.GetOrganizationList();
List<SelectListItem> oOrganizationNameList = new List<SelectListItem>();
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<SelectListItem> oStateNameList = new List<SelectListItem>();
//ViewBag.StateList = oStateNameList;
List<StateModel> oStateList = objUserInventoryRepository.GetStateList();
List<SelectListItem> oStateNameList = new List<SelectListItem>();
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<SelectListItem> item1 = new List<SelectListItem>();
ViewBag.VehicleModelNo = item1.OrderBy(o => o.Text);
//Get languages List
List<LanguageModel> oLanguageList = objDropDownDataRepository.GetLanguagesList();
List<SelectListItem> oLanguageNameList = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Add vecv user
/// </summary>
/// <param name="model">user model</param>
/// <returns>return json success true or false</returns>
[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
/// <summary>
/// Get non vecv user view
/// </summary>
/// <returns>return view</returns>
public ActionResult ManageDealerInventory()
{
return View();
}
#region Add Dealer
/// <summary>
/// Get add non vecv user form
/// </summary>
/// <returns>return form view</returns>
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<RoleModel> oRoleList = oRoleClient.GetRole().ToList();
List<RoleModel> 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<SelectListItem> oRoleNameList = new List<SelectListItem>();
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<OrganizationModel> oOrganizationList = objUserInventoryRepository.GetOrganizationList();
List<SelectListItem> oOrganizationNameList = new List<SelectListItem>();
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<StateModel> oStateList = objUserInventoryRepository.GetStateList();
List<SelectListItem> oStateNameList = new List<SelectListItem>();
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<DealerModel> oNonUserDealerList = objUserInventoryRepository.GetNonUserDealersList();
List<SelectListItem> item11 = new List<SelectListItem>();
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<LanguageModel> oLanguageList = objDropDownDataRepository.GetLanguagesList();
List<SelectListItem> oLanguageNameList = new List<SelectListItem>();
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<ManageFleet> oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList();
List<SelectListItem> item12 = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Add non-vecv user
/// </summary>
/// <param name="model">user model</param>
/// <returns>return json success true or false</returns>
[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
/// <summary>
/// Get city list based on state id
/// </summary>
/// <param name="stateVal">State id</param>
/// <returns>returns city list</returns>
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<CityModel> oCityList = objUserInventoryRepository.GetCityList(stateVal);
List<SelectListItem> oCityNameList = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Get region name for autocomplete
/// </summary>
/// <returns>returns region name list</returns>
public JsonResult GetRegionNameList()
{
objLog.AddLogFile("ManageUserInventory_GetRegionNameList", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
try
{
objUserInventoryRepository = new UserInventoryRepository();
//Get region list
List<RegionModel> regionModel = objUserInventoryRepository.GetRegionModel().OrderBy(o => o.RegionName).ToList();
regionModel.RemoveAt(0);
List<string> regionList = new List<string>();
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;
}
}
/// <summary>
/// check user if exist already
/// </summary>
/// <param name="UserName">user name</param>
/// <returns>return true if exist otherwise false</returns>
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;
}
}
/// <summary>
/// check email id if exist already
/// </summary>
/// <param name="EmailId">user's email id</param>
/// <returns></returns>
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;
}
}
/// <summary>
/// check if user name is exist or not in auth engine db
/// </summary>
/// <param name="userName">input user name string</param>
/// <returns>return true or false</returns>
[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();
}
}
}
/// <summary>
/// Get organization name non-vecv user name wise
/// </summary>
/// <param name="dealerId">non-vecv user(dealers) id</param>
/// <returns>return json of organization name and id</returns>
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<DealerModel> 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<OrganizationModel> 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
/// <summary>
/// Get Principle Dealer view
/// </summary>
/// <returns>return view</returns>
public ActionResult ManagePrincipleDealerInventory()
{
return View();
}
#region add principal dealer
/// <summary>
/// Get add Principle Dealer user form
/// </summary>
/// <returns>return form view</returns>
[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<OrganizationModel> oOrganizationList = objUserInventoryRepository.GetOrganizationList();
List<SelectListItem> oOrganizationNameList = new List<SelectListItem>();
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<StateModel> oStateList = objUserInventoryRepository.GetStateList();
List<SelectListItem> oStateNameList = new List<SelectListItem>();
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<ManageFleet> oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList();
List<SelectListItem> item12 = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Add Principle Dealer user
/// </summary>
/// <param name="model">user model</param>
/// <returns>return json success true or false</returns>
[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
/// <summary>
/// Get view to show Dealer Principal Details
/// </summary>
/// <param name="dealerPrincipalId">Dealer Principal's Id</param>
/// <returns>return partial view</returns>
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
/// <summary>
/// Get add Principle Dealer user form
/// </summary>
/// <returns>return form view</returns>
[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<UserCreateModel> 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<OrganizationModel> oOrganizationList = objUserInventoryRepository.GetOrganizationList();
List<SelectListItem> oOrganizationNameList = new List<SelectListItem>();
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<StateModel> oStateList = objTicketAdministrationRepository.GetStateListRegionWise(regionVal);
List<SelectListItem> oStateNameList = new List<SelectListItem>();
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<CityModel> oCityList = objUserInventoryRepository.GetCityList(stateVal);
List<SelectListItem> oCityNameList = new List<SelectListItem>();
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<ManageFleet> oDealerList = objInventoryRepository.GetDealerList(_LoginUserId, "", "").Where(p => p.IsDeleted == false).ToList();
List<SelectListItem> item12 = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Add vecv user
/// </summary>
/// <param name="model">user model</param>
/// <returns>return json success true or false</returns>
[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<RoleModel> oRoleList = oRoleClient.GetRole().OrderBy(o => o.RoleName).ToList();
List<RoleModel> 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<UserCreateModel> 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<SelectListItem> oRoleNameList = new List<SelectListItem>();
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<OrganizationModel> oOrganizationList = objUserInventoryRepository.GetOrganizationList();
List<SelectListItem> oOrganizationNameList = new List<SelectListItem>();
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<StateModel> oStateList = objTicketAdministrationRepository.GetStateListRegionWise(regionVal);
List<SelectListItem> oStateNameList = new List<SelectListItem>();
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<CityModel> oCityList = objUserInventoryRepository.GetCityList(stateVal);
List<SelectListItem> oCityNameList = new List<SelectListItem>();
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<SelectListItem> item1 = new List<SelectListItem>();
ViewBag.VehicleModelNo = item1.OrderBy(o => o.Text);
//Get languages List
List<LanguageModel> oLanguageList = objDropDownDataRepository.GetLanguagesList();
List<SelectListItem> oLanguageNameList = new List<SelectListItem>();
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;
}
}
/// <summary>
/// Add vecv user
/// </summary>
/// <param name="model">user model</param>
/// <returns>return json success true or false</returns>
[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
/// <summary>
/// Get add non vecv user form
/// </summary>
/// <returns>return form view</returns>
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
/// <summary>
/// Reset the pwd of non vecv user form
/// </summary>
/// <returns>return form view</returns>
[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<UserModel> lsUserModel = oUserClient.GetUser().ToList();
//Get user details list by user name
List<UserCreateModel> 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
/// <summary>
/// Reset the pwd of non vecv user form
/// </summary>
/// <returns>return form view</returns>
[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
}
}