public ActionResult ChangePassword(int?userid) { CustomerUserViewModel user = new CustomerUserViewModel(); user = customerUserService.getSingleCustomerList(userid); return(PartialView(user)); }
public ActionResult New() { var customerToReturn = new Customer(); var form = "CustomerFormUser"; if (User.IsInRole(RoleNames.Administrator) || User.IsInRole(RoleNames.GarageOwner)) { form = "CustomerForm"; var viewModel = new CustomerUserViewModel() { Customer = new Customer(), ApplicationUser = _context.Users.SingleOrDefault(c => c.Id == customerToReturn.ApplicationUserId) }; return(View(form, viewModel)); } else if (User.IsInRole(RoleNames.Customer)) { form = "AlreadyInRole"; return(View(form)); } else { return(View(form)); } }
public ActionResult _List(string name = "", int pageNo = 1, int pageSize = 10) { CustomerUserViewModel customerViewModel = new CustomerUserViewModel(); var customerList = customerUserService.getUserCustomerList(name, pageNo, pageSize); customerViewModel.customeruserPagedList = new StaticPagedList <CustomerUserViewModel>(customerList, pageNo, pageSize, (customerList.Count == 0) ? 0 : customerList.FirstOrDefault().TotalCount); return(PartialView(customerViewModel)); }
public ActionResult ChangePassword(CustomerUserViewModel customerUserViewModel) { PasswordHasher pass = new PasswordHasher(); customerUserViewModel.NewPassword = pass.HashPassword(customerUserViewModel.NewPassword); var message = customerUserService.ChangePassword(customerUserViewModel); return(Json(message, JsonRequestBehavior.AllowGet)); }
public ReturnBaseMessageModel ChangePassword(CustomerUserViewModel customerUserViewModel) { var singleUser = uow.Repository <CustomerUserTable>().FindBy(x => x.UserId == customerUserViewModel.UserId).SingleOrDefault(); singleUser.PasswordHash = customerUserViewModel.NewPassword; uow.Repository <CustomerUserTable>().Edit(singleUser); uow.Commit(); returnBaseMessageModel.Msg = "Password Edited Sucessfully"; returnBaseMessageModel.Success = true; return(returnBaseMessageModel); }
public async Task <ActionResult> Users(int id) { Customer customer = await customerService.FindCustomersByIDAsync(id); if (customer == null) { return(HttpNotFound()); } var model = new CustomerUserViewModel(customer); return(View(model)); }
public ActionResult Create(CustomerUserViewModel customerUser) { try { ViewBag.Title = "Sign Up"; string serializedObject = JsonConvert.SerializeObject(customerUser.User); var content = new StringContent(serializedObject); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var insertUserResponse = client.PostAsync("User/", content).Result; string insertUserResult = insertUserResponse.Content.ReadAsStringAsync().Result; if (insertUserResponse.StatusCode == System.Net.HttpStatusCode.OK) { // returns the guid Id of the inserted record customerUser.User.Id = JsonConvert.DeserializeObject <Guid>(insertUserResult); customerUser.Customer.UserId = customerUser.User.Id; customerUser.Customer.FirstName = customerUser.User.FirstName; customerUser.Customer.LastName = customerUser.User.LastName; // save customer serializedObject = JsonConvert.SerializeObject(customerUser.Customer); content = new StringContent(serializedObject); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var insertCustomerResponse = client.PostAsync("Customer/", content).Result; string insertCustomerResult = insertCustomerResponse.Content.ReadAsStringAsync().Result; if (insertCustomerResponse.StatusCode == System.Net.HttpStatusCode.OK) { // returns the guid Id of the inserted record customerUser.Customer.Id = JsonConvert.DeserializeObject <Guid>(insertCustomerResult); return(RedirectToAction("Index", "Home")); } else { throw new Exception(insertCustomerResult); } } else { throw new Exception(insertUserResult); } } catch (Exception ex) { ViewBag.Title = "Sign Up"; ViewBag.Error = ex.Message; return(View(customerUser)); } }
public ReturnBaseMessageModel SaveCustomerUser(CustomerUserViewModel user) { try { var singleUser = uow.Repository <CustomerUserTable>().FindBy(x => x.UserId == user.UserId).SingleOrDefault(); if (singleUser == null) { singleUser = new CustomerUserTable(); singleUser.PasswordHash = user.PasswordHash; singleUser.CustomerId = user.CustomerId; singleUser.EffDate = user.EffDate; singleUser.TillDate = user.TillDate; singleUser.UserName = user.UserName; singleUser.MTId = Convert.ToInt32(user.MTId); singleUser.Email = user.Email; singleUser.IsActive = user.IsActive; singleUser.IsUnlimited = user.IsUnlimited; uow.Repository <CustomerUserTable>().Add(singleUser); uow.Commit(); returnBaseMessageModel.Msg = "Customer User Added Sucessfully"; returnBaseMessageModel.Success = true; } else { singleUser.CustomerId = user.CustomerId; singleUser.EffDate = user.EffDate; singleUser.TillDate = user.TillDate; singleUser.UserName = user.UserName; singleUser.MTId = Convert.ToInt32(user.MTId); singleUser.Email = user.Email; singleUser.IsActive = user.IsActive; singleUser.IsUnlimited = user.IsUnlimited; uow.Repository <CustomerUserTable>().Edit(singleUser); uow.Commit(); returnBaseMessageModel.Msg = "Customer User Edited Sucessfully"; returnBaseMessageModel.Success = true; } return(returnBaseMessageModel); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(Guid id, CustomerUserViewModel customerUser) { try { ViewBag.Title = "Edit My Profile"; string serializedObject = JsonConvert.SerializeObject(customerUser.User); var content = new StringContent(serializedObject); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var insertUserResponse = client.PutAsync("User/", content).Result; string insertUserResult = insertUserResponse.Content.ReadAsStringAsync().Result; if (insertUserResponse.StatusCode == System.Net.HttpStatusCode.OK) { // We only collected user first name and Last name. Make customers the same. customerUser.Customer.FirstName = customerUser.User.FirstName; customerUser.Customer.LastName = customerUser.User.LastName; // save customer serializedObject = JsonConvert.SerializeObject(customerUser.Customer); content = new StringContent(serializedObject); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var insertCustomerResponse = client.PutAsync("Customer/", content).Result; string insertCustomerResult = insertCustomerResponse.Content.ReadAsStringAsync().Result; if (insertCustomerResponse.StatusCode == System.Net.HttpStatusCode.OK) { HttpContext.Session.SetObject("user", customerUser.User); HttpContext.Session.SetObject("customer", customerUser.Customer); return(RedirectToAction("Index", "Home")); } else { throw new Exception(insertCustomerResult); } } else { throw new Exception(insertUserResult); } } catch (Exception ex) { ViewBag.Title = "Edit My Profile"; ViewBag.Error = ex.Message; return(View(customerUser)); } }
public async Task <ActionResult> CustomerUsers(Guid id, CustomerUserViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GenerateErrorMessageDetails())); } var result = await customerUsersManager.UpdateCustomerUser(id, model); if (result.IsValid) { return(Json(string.Empty)); } return(BadRequest(result.Error.Value.GetConcatString())); }
public ActionResult Create(int?userid) { CustomerUserViewModel user = new CustomerUserViewModel(); if (userid != 0 && userid != null) { user = customerUserService.getSingleCustomerList(userid); ViewBag.Customer = customerUserService.getCustomerName(user.CustomerId); ViewBag.Id = userid; } else { ViewBag.Id = 0; } return(PartialView(user)); }
/// <summary> /// Creates new user record in database and token service. /// User enabled by default. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public async Task <CreateCustomerUserResultDto> CreateCustomerUser(CustomerUserViewModel model) { var customerUser = Mapper.Map <CustomerUserViewModel, CustomerUser>(model); var bearerToken = this.authDataStorage.GetToken(); customerUser.CustomerId = CustomerContext.Current.Customer.Id; var result = await customerUsersService.CreateCustomerUser(customerUser, bearerToken); if (result.IsValid && !model.DoNotSendInvitation) { var passwordExpirationDays = CustomerContext.Current.Customer.PasswordExpirationDays; await emailManager.SendActivationEmail(customerUser, passwordExpirationDays); } return(result); }
public ActionResult CustomerUserSave(CustomerUserViewModel customerUserViewModel) { try { if (customerUserViewModel.UserId == 0) { PasswordHasher pass = new PasswordHasher(); customerUserViewModel.PasswordHash = pass.HashPassword(customerUserViewModel.PasswordHash); } var message = customerUserService.SaveCustomerUser(customerUserViewModel); return(Json(message, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
// GET: UserController/Edit/5 public ActionResult Edit(Guid id) { if (Authenticate.IsAuthenticated(HttpContext)) { ViewBag.Title = "Edit My Profile"; CustomerUserViewModel customerUser = new CustomerUserViewModel { User = HttpContext.Session.GetObject <User>("user"), Customer = HttpContext.Session.GetObject <Customer>("customer"), }; return(View(customerUser)); } else { return(RedirectToAction("Login", "User", new { returnUrl = UriHelper.GetDisplayUrl(HttpContext.Request) })); } }
public ActionResult List() { try { CustomerUserViewModel customerViewModel = new CustomerUserViewModel(); var customerList = customerUserService.getUserCustomerList("", 1, 10); customerViewModel.customeruserPagedList = new StaticPagedList <CustomerUserViewModel>(customerList, 1, 10, (customerList.Count == 0) ? 0 : customerList.FirstOrDefault().TotalCount); //foreach (var item in customerList) //{ // customerViewModel.customerViewModelList.Add(item); //} return(PartialView(customerViewModel)); } catch (Exception ex) { throw ex; } }
/// <summary> /// Updates customer user data and access to sites. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public async Task <UpdateCustomerUserResultDto> UpdateCustomerUser(Guid userId, CustomerUserViewModel model) { var bearerToken = authDataStorage.GetToken(); var customerUser = Mapper.Map <CustomerUserViewModel, CustomerUser>(model); customerUser.Id = userId; customerUser.CustomerId = CustomerContext.Current.Customer.Id; return(await customerUsersService.UpdateCustomerUser(customerUser, bearerToken)); }
public async Task <IActionResult> Register(CustomerUserViewModel model) { if (ModelState.IsValid) { //Creating phone number list List <PhoneNumber> phoneList = new List <PhoneNumber>() { new PhoneNumber() { Number = model.PhoneNumber1 } }; //Checking for second phone if (model.PhoneNumber2 != null) { phoneList.Add(new PhoneNumber() { Number = model.PhoneNumber2 }); } //Creating User var user = new CustomerUser() { FullName = model.FullName, Cpf = model.Cpf, Rg = model.Rg, Sex = model.Sex, Birthday = model.Birthday, Cep = model.Cep, Street = model.Street, Number = model.Number, Neighborhood = model.Neighborhood, Complement = model.Complement, City = model.City, State = model.State, Email = model.Email, UserName = model.Email, PhoneNumbers = phoneList }; //Creating user var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //Good to go! await signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } else { foreach (var error in result.Errors) { if (error.Code.Equals("DuplicateUserName")) { ModelState.AddModelError(string.Empty, "E-mail já registrado no sistema!"); } else { ModelState.AddModelError(string.Empty, error.Description); } } } } return(View(model)); }
public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var form = "CustomerFormUser"; if (User.IsInRole(RoleNames.Administrator) || User.IsInRole(RoleNames.GarageOwner) || User.IsInRole(RoleNames.Customer)) { form = "CustomerForm"; var viewModel = new CustomerUserViewModel() { Customer = customer, ApplicationUser = _context.Users.SingleOrDefault(c => c.Id == customer.ApplicationUserId) }; return(View(form, viewModel)); } else { return(View(form)); } } var currentUserID = User.Identity.GetUserId(); var userIsCustomer = _context.Customers.SingleOrDefault(c => c.ApplicationUserId == currentUserID); var userIsGarage = _context.Garages.SingleOrDefault(c => c.ApplicationUserId == currentUserID); var objectIsCustomer = _context.Customers.SingleOrDefault(c => c.ApplicationUserId == customer.ApplicationUserId); var objectIsGarage = _context.Garages.SingleOrDefault(c => c.ApplicationUserId == customer.ApplicationUserId); var userExists = _context.Users.SingleOrDefault(u => u.Id == customer.ApplicationUserId); //******** Come here if form is valid if (customer.ID == 0) { //user is a Customer already if (User.IsInRole(RoleNames.Customer)) { return(View("AlreadyInRoleGeneral")); } else { //checking if the user has a role, a customer cannot be a garage in the same time if ((objectIsGarage == null || objectIsCustomer == null) && userExists != null) { security.AddUserToRole(customer.ApplicationUserId, RoleNames.Customer); _context.Customers.Add(customer); } else if (userIsCustomer == null || userIsGarage == null) //&& //_context.Users.SingleOrDefault(u => u.Id == User.Identity.GetUserId()) != null { security.AddUserToRole(currentUserID, RoleNames.Customer); customer.ApplicationUserId = currentUserID; _context.Customers.Add(customer); } //if there is no userID on the file matching the one returned from the form else if (_context.Users.SingleOrDefault(u => u.Id == customer.ApplicationUserId) == null) { return(View("NeedToRegisterBefore")); } //there is a user with this UserID in the customers or garage role else { return(View("AlreadyInRoleGeneral")); } } } //needs to be finished else { var customerInDB = _context.Customers.Single(c => c.ID == customer.ID); if (User.IsInRole(RoleNames.Customer)) { //Manually update the fields I want. customerInDB.FirstName = customer.FirstName; customerInDB.LastName = customer.LastName; customerInDB.Address = customer.Address; customerInDB.PhoneNumber = customer.PhoneNumber; customerInDB.ApplicationUserId = User.Identity.GetUserId(); security.AddUserToRole(currentUserID, RoleNames.Customer); } else if (User.IsInRole(RoleNames.Administrator) || User.IsInRole(RoleNames.GarageOwner)) { var UserId = _context.Users.SingleOrDefault(c => c.Id == customer.ApplicationUserId); //Manually update the fields I want. customerInDB.FirstName = customer.FirstName; customerInDB.LastName = customer.LastName; customerInDB.Address = customer.Address; customerInDB.PhoneNumber = customer.PhoneNumber; customerInDB.ApplicationUserId = customer.ApplicationUserId; security.AddUserToRole(customer.ApplicationUserId, RoleNames.Customer); } } _context.SaveChanges(); if (User.IsInRole(RoleNames.Administrator) || User.IsInRole(RoleNames.GarageOwner)) { return(RedirectToAction("Index", "Customers")); } else { return(RedirectToAction("Index", "Home")); } }