public ActionResult Create([Bind(Include = "UserId,UserName,FirstName,Password,UserEmailAddress,CompanyID,IsActive")] UserModel usermodel) { UserPermissionAction("user", RoleAction.create.ToString()); CheckPermission(); try { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please fill the required field with valid data"; ViewBag.CompanyID = new SelectList(_CompanyService.GetCompanies(), "CompanyID", "CompanyName", usermodel.CompanyID); if (ModelState.IsValid) { User objUser = _UserService.GetUsers().Where(c => c.UserName.ToLower() == usermodel.UserName.ToLower() || c.UserEmailAddress.ToLower() == usermodel.UserEmailAddress.ToLower()).FirstOrDefault();//db.Users.Where(x => x.UserName.ToLower() == users.UserName.ToLower() || x.UserEmailAddress.ToLower() == users.UserEmailAddress.ToLower()).FirstOrDefault(); if (objUser == null) { Mapper.CreateMap <CommunicationApp.Models.UserModel, CommunicationApp.Entity.User>(); CommunicationApp.Entity.User user = Mapper.Map <CommunicationApp.Models.UserModel, CommunicationApp.Entity.User>(usermodel); _UserService.InsertUser(user); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = "user is saved successfully."; return(RedirectToAction("Index")); } else { TempData["ShowMessage"] = "error"; if (objUser.UserName.ToLower() == objUser.UserName.ToLower()) //Check User Name { TempData["MessageBody"] = objUser.UserName + " is already exist."; } else if (objUser.UserEmailAddress.ToLower() == objUser.UserEmailAddress.ToLower()) //Check User Name { TempData["MessageBody"] = objUser.UserEmailAddress + " is already exist."; } else { TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on " + objUser.UserName + " user."; } } } var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); } catch (Exception ex) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Some problem occured while proccessing save operation on " + usermodel.UserName + " user."; } return(View(usermodel)); }
public ActionResult Create([Bind(Include = "CustomerId,TrebId,WebsiteUrl,ApplicationID,Password,CompanyID,UserId,PhotoPath,FirstName,LastName,MiddleName,EmailID,MobileNo,CountryID,StateID,CityID,ZipCode,Latitude,Longitude,CreatedOn,LastUpdatedOn,MobileVerifyCode,EmailVerifyCode,IsMobileVerified,IsEmailVerified,IsActive,AdminCompanyAddress")] AdminModel AdminModel, HttpPostedFileBase file, HttpPostedFileBase Logo) { TempData["ShowMessage"] = ""; TempData["MessageBody"] = ""; UserPermissionAction("admin", RoleAction.create.ToString()); CheckPermission(); Mapper.CreateMap <CommunicationApp.Models.AdminModel, CommunicationApp.Entity.Customer>(); CommunicationApp.Entity.Customer Customer = Mapper.Map <CommunicationApp.Models.AdminModel, CommunicationApp.Entity.Customer>(AdminModel); if (ModelState.IsValid) { var customerFound = _CustomerService.GetCustomers().Where(x => x.EmailId == Customer.EmailId || x.MobileNo == Customer.MobileNo || x.WebsiteUrl == Customer.WebsiteUrl).FirstOrDefault(); if (customerFound == null) { //Save Company of admin Company Company = new Entity.Company(); Company.WebSite = Customer.WebsiteUrl; Company.CountryID = 1; Company.StateID = 1; Company.CityID = 1; Company.CompanyAddress = AdminModel.AdminCompanyAddress != "" ? AdminModel.AdminCompanyAddress : "*****@*****.**"; Company.CompanyName = AdminModel.CompanyName != null ? AdminModel.CompanyName : "Company"; Company.EmailID = "*****@*****.**"; Company.PhoneNo = "123456987"; Company.IsActive = true; if (Logo != null) { Company.LogoPath = Savefile(Logo); } _CompanyService.InsertCompany(Company); //Insert User first CommunicationApp.Entity.User user = new CommunicationApp.Entity.User(); //user.UserId =0; //New Case user.FirstName = Customer.FirstName; user.TrebId = Customer.TrebId; user.LastName = Customer.LastName; user.UserName = Customer.EmailId; user.Password = SecurityFunction.EncryptString(AdminModel.Password); user.UserEmailAddress = Customer.EmailId; user.CompanyID = Company.CompanyID; user.CreatedOn = DateTime.Now; user.LastUpdatedOn = DateTime.Now; user.TrebId = "0000000"; user.IsActive = true; _UserService.InsertUser(user); //End : Insert User first var UserID = user.UserId; if (user.UserId > 0) { //Insert User Role CommunicationApp.Entity.UserRole userRole = new CommunicationApp.Entity.UserRole(); userRole.UserId = user.UserId; userRole.RoleId = 2; //By Default set new Admin/user role id=2 _UserRoleService.InsertUserRole(userRole); //End : Insert User Role //Insert the Customer Customer.FirstName = Customer.FirstName; Customer.UserId = user.UserId; Customer.Designation = "Admin"; Customer.MobileVerifyCode = CommonCls.GetNumericCode(); Customer.EmailVerifyCode = CommonCls.GetNumericCode(); Customer.MobileVerifyCode = "9999"; Customer.EmailVerifyCode = "9999"; Customer.CreatedOn = DateTime.Now; Customer.CompanyID = Company.CompanyID; Customer.Address = ""; Customer.ZipCode = ""; Customer.IsEmailVerified = true; var PhotoPath = ""; if (file != null) { PhotoPath = Savefile(file); } Customer.PhotoPath = PhotoPath; Customer.IsMobileVerified = false; Customer.ApplicationId = AdminModel.ApplicationId; Customer.DeviceSerialNo = AdminModel.DeviceSerialNo; Customer.DeviceType = AdminModel.DeviceType; Customer.IsUpdated = false; Customer.IsNotificationSoundOn = true; if (Customer.FirstName == null) { Customer.FirstName = ""; } if (Customer.LastName == null) { Customer.LastName = ""; } if (Customer.MiddleName == null) { Customer.MiddleName = ""; } _CustomerService.InsertCustomer(Customer); var CustomerID = Customer.CustomerId.ToString(); AdminModel.CustomerId = Customer.CustomerId; TempData["ShowMessage"] = "Success"; TempData["MessageBody"] = "Admin successfully register."; } } else { if (customerFound.EmailId == AdminModel.EmailID) { TempData["ShowMessage"] = "Error"; TempData["MessageBody"] = "Email is already exist."; } else if (customerFound.MobileNo == AdminModel.MobileNo) { TempData["ShowMessage"] = "Error"; TempData["MessageBody"] = "MobileNos is already exist."; } else { TempData["ShowMessage"] = "Error"; TempData["MessageBody"] = "Some error occured."; } } } else { var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); TempData["ShowMessage"] = "Error"; TempData["MessageBody"] = "Please fill the required data."; return(View(AdminModel)); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "UserId,UserName,Password,UserEmailAddress,CompanyID,IsActive")] UserModel usermodel, int id) { UserPermissionAction("user", RoleAction.edit.ToString()); CheckPermission(); try { ViewBag.CompanyID = new SelectList(_CompanyService.GetCompanies(), "CompanyID", "CompanyName", usermodel.CompanyID); TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please fill the required field with valid data"; if (ModelState.IsValid) { User objUser = _UserService.GetUsers().Where(c => c.UserName.ToLower() == usermodel.UserName.ToLower() || c.UserEmailAddress.ToLower() == usermodel.UserEmailAddress.ToLower() && c.UserId != usermodel.UserId).FirstOrDefault(); //db.Users.Where(x => (x.UserName.ToLower() == user.UserName.ToLower() || x.UserEmailAddress.ToLower() == user.UserEmailAddress.ToLower()) && x.UserId != user.UserId).FirstOrDefault(); if (objUser == null) { Mapper.CreateMap <CommunicationApp.Models.UserModel, CommunicationApp.Entity.User>(); CommunicationApp.Entity.User user = Mapper.Map <CommunicationApp.Models.UserModel, CommunicationApp.Entity.User>(usermodel); //Update the User Info User us = _UserService.GetUsers().Where(c => c.UserId == id).FirstOrDefault();//db.Users.Where(z => z.UserId == id).FirstOrDefault(); us.UserName = user.UserName; us.Password = SecurityFunction.EncryptString(user.Password); us.UserEmailAddress = user.UserEmailAddress; us.CompanyID = user.CompanyID; us.IsActive = user.IsActive; _UserService.UpdateUser(us); //db.SaveChanges(); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = user.UserName + " is update successfully."; return(RedirectToAction("Index")); } else { TempData["ShowMessage"] = "error"; if (objUser.UserName.ToLower() == usermodel.UserName.ToLower()) //Check User Name { TempData["MessageBody"] = usermodel.UserName + " is already exist."; } else if (objUser.UserEmailAddress.ToLower() == usermodel.UserEmailAddress.ToLower()) //Check User Name { TempData["MessageBody"] = usermodel.UserEmailAddress + " is already exist."; } else { TempData["MessageBody"] = "Some unknown problem occured while proccessing update operation on " + usermodel.UserName + " user."; } } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { //Exception raise = dbEx; //foreach (var validationErrors in dbEx.EntityValidationErrors) //{ // foreach (var validationError in validationErrors.ValidationErrors) // { // string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException // raise = new InvalidOperationException(message, raise); // } //} //throw raise; TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Some problem occured while proccessing update operation on " + usermodel.UserName + " user."; } return(View(usermodel)); }
public ActionResult Register([Bind(Include = "CustomerId,FirstName,LastName,EmailId,MobileNo,Password")] CustomerModel Customermodel) { try { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please fill the required field with valid data"; if (ModelState.IsValid) { Mapper.CreateMap <CommunicationApp.Models.CustomerModel, CommunicationApp.Entity.Customer>(); CommunicationApp.Entity.Customer Customer = Mapper.Map <CommunicationApp.Models.CustomerModel, CommunicationApp.Entity.Customer>(Customermodel); Customer Customers = _CustomerService.GetCustomers().Where(c => c.FirstName.Trim() == Customer.FirstName.Trim() || c.EmailId.Trim() == Customer.EmailId.Trim() || c.MobileNo.Trim() == Customer.MobileNo.Trim()).FirstOrDefault(); if (Customers == null) { //There is no session in API Controller. So we will find solution in future Customer.CompanyID = 1; //Insert User first string Password = Customermodel.Password; CommunicationApp.Entity.User user = new CommunicationApp.Entity.User(); //user.UserId =0; //New Case user.FirstName = Customer.FirstName; user.LastName = Customer.LastName; user.UserName = Customer.MobileNo; // insert mobile number// user.Password = SecurityFunction.EncryptString(Password); //No password right now. We will create send email procedure for password recovery user.UserEmailAddress = Customer.EmailId; user.CompanyID = Customer.CompanyID; user.IsActive = true; _UserService.InsertUser(user); //End : Insert User first if (user.UserId > 0) { //Insert User Role CommunicationApp.Entity.UserRole userRole = new CommunicationApp.Entity.UserRole(); userRole.UserId = user.UserId; userRole.RoleId = 3; //By Default set new Customer/user role id=3 _UserroleService.InsertUserRole(userRole); //End : Insert User Role //Insert the Customer //Save the Driver photo in Folder //Check SubPath Exist or Not Customer.UserId = user.UserId; Customer.Longitude = 0; Customer.Latitude = 0; Customer.ApplicationId = ""; _CustomerService.InsertCustomer(Customer); //Save Operation //End : Insert the Customer } TempData["ShowMessage"] = "success"; TempData["MessageBody"] = Customer.FirstName + " is saved successfully."; ModelState.Clear(); return(RedirectToAction("LogOn", "Account")); } else { TempData["ShowMessage"] = "error"; if (Customers.FirstName.Trim() == Customermodel.FirstName.Trim()) { TempData["MessageBody"] = Customermodel.FirstName + " is already exists."; } else if (Customers.EmailId.Trim() == Customermodel.EmailID.Trim()) { TempData["MessageBody"] = Customermodel.EmailID + " is already exists."; } else if (Customers.MobileNo.Trim() == Customermodel.MobileNo.Trim()) { TempData["MessageBody"] = Customermodel.MobileNo + " is already exists."; } else { TempData["MessageBody"] = "Please fill the required field with valid data"; } //_DriverService.UpdateDriver(driver); //Update Operation } } } catch (RetryLimitExceededException) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on " + Customermodel.FirstName + " "; } return(View(Customermodel)); }