public ActionResult UsersCreate(RegisterCustomerAuditorUserViewModel model) { if (ModelState.IsValid) { AdminUser user = (AdminUser)model.GetUser(); var result = userManager.Create((ApplicationUser)user, model.Password); if (result.Succeeded) { var customerAuditor = new CustomerAuditor(null, base.CurrentCustomerID, user.Id); customerAuditorRepository.Create(customerAuditor); //workflowMessageService.SendContractorUserRegistrationNotificationMessage(model); return(RedirectToAction("Users", "CustomerAuditors")); } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> UsersDelete(int customerAuditorID, int customerID, string userId) { if ((userId == null) || (userId.ToString().Length == 0)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //var user = customerAuditorRepository.FindCustomerAuditorsByUserIDAsync(userId); //if (user == null) //{ // return HttpNotFound(); //} //Falta eliminar la relacion del usuario con los Clientes //await customerAuditorRepository.DeleteByUserIdAsync(userId); var user = await userManager.FindByIdAsync(userId); if (user == null) { return(HttpNotFound()); } var userAuditor = new CustomerAuditor() { CustomerAuditorID = customerAuditorID, CustomerID = customerID, User = (AdminUser)user, UserId = userId }; var model = new EditCustomerAuditorUserViewModel(userAuditor); return(View(model)); }
public EditAssignCustomerViewModel(CustomerAuditor customerAuditor) { this.CustomerAuditorID = (int)customerAuditor.CustomerAuditorID; this.CustomerID = customerAuditor.CustomerID; this.UserID = customerAuditor.UserId; this.UserName = customerAuditor.User.UserName; this.CustomerDesc = customerAuditor.Customer.CompanyName + " (" + customerAuditor.Customer.TaxIdNumber + ")"; }
// Allow Initialization with an instance of ApplicationUser: public EditCustomerAuditorUserViewModel(CustomerAuditor user) { this.CustomerAuditorID = user.CustomerAuditorID; this.CustomerID = user.CustomerID; this.UserId = user.UserId; this.UserName = user.User.UserName; this.FirstName = user.User.FirstName; this.LastName = user.User.LastName; this.Email = user.User.Email; }
public CustomerAuditorViewModel(CustomerAuditor customerAuditor) { this.CustomerAuditorID = customerAuditor.CustomerAuditorID; this.CustomerID = customerAuditor.CustomerID; this.UserId = customerAuditor.UserId; this.User = customerAuditor.User; this.UserName = customerAuditor.User.UserName; this.FirstName = customerAuditor.User.FirstName; this.LastName = customerAuditor.User.LastName; this.Email = customerAuditor.User.Email; }
public CustomerAuditor GetCustomer() { var customer = new CustomerAuditor() { CustomerAuditorID = this.CustomerAuditorID, CustomerID = this.CustomerID, UserId = this.UserID }; return(customer); }
public async Task <ActionResult> UsersDeleteConfirmed(int customerAuditorID) { CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID); if (customerAuditor == null) { return(HttpNotFound()); } await customerAuditorRepository.Delete(customerAuditorID); return(RedirectToAction("Users", "CustomerAuditors")); }
public async Task <ActionResult> CustomersDelete(int customerAuditorID, string userID) { CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID); if (customerAuditor == null) { return(HttpNotFound()); } var model = new EditAssignCustomerViewModel(customerAuditor); return(View(model)); }
public async Task <ActionResult> UsersEdit(int customerAuditorID) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID); if (customerAuditor == null) { return(HttpNotFound()); } var model = new EditCustomerAuditorUserViewModel(customerAuditor); return(View(model)); }
public async Task <ActionResult> UsersDelete(int customerAuditorID) { //if ((customerAuditorID == null) || (username.ToString().Length == 0)) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID); if (customerAuditor == null) { return(HttpNotFound()); } var model = new EditCustomerAuditorUserViewModel(customerAuditor); return(View(model)); }
public async Task <ActionResult> UsersEdit([Bind(Include = "CustomerAuditorID,UserId,UserName,FirstName,LastName,Email")] EditCustomerAuditorUserViewModel customerAuditorVM) { if (ModelState.IsValid) { CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorVM.CustomerAuditorID.Value); customerAuditor.User.Id = customerAuditorVM.UserId; customerAuditor.User.UserName = customerAuditorVM.UserName; customerAuditor.User.FirstName = customerAuditorVM.FirstName; customerAuditor.User.LastName = customerAuditorVM.LastName; customerAuditor.User.Email = customerAuditorVM.Email; customerAuditorRepository.Update(customerAuditor); return(RedirectToAction("Users")); } return(View(customerAuditorVM)); }
public async Task <ActionResult> CustomersCreate(EditAssignCustomerViewModel model) { if (ModelState.IsValid) { CustomerAuditor customer = (CustomerAuditor)model.GetCustomer(); customer.UserId = model.UserID; try { await customerAuditorRepository.CreateAsync(customer); return(RedirectToAction("AssignedCustomers", "CustomerAdminAuditors", new { userID = model.UserID })); } catch (Exception e) { var errors = string.Join(",", e.Message); ModelState.AddModelError(string.Empty, errors); } } ViewBag.CustomerID = new SelectList(customerRepository.UnAssignedCustomers(model.UserID), "CustomerID", "CompanyName"); // If we got this far, something failed, redisplay form return(View(model)); }