/// <summary> /// Takes Customer information annd updates the database with the new information /// </summary> /// <param name="customer"></param> public void UpdateCustomer(Core.Models.Customer customer) { DataAccess.SQLData.Customer currentCustomer = _context.Customer.Find(customer.EmailAddress); DataAccess.SQLData.Customer updatedCustomer = Mapper.MapSQLCustomer(customer); _context.Entry(currentCustomer).CurrentValues.SetValues(updatedCustomer); Save(); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> Register(RegisterCustomerViewModel model) { if (ModelState.IsValid) { #region Check for duplicate username or email if (UserRepo.UserNameExists(model.PhoneNumber)) { ModelState.AddModelError("", Resources.Resource.PhoneNumberExists); return(View(model)); } if (UserRepo.EmailExists(model.Email)) { ModelState.AddModelError("", Resources.Resource.EmailExists); return(View(model)); } #endregion var user = new User { UserName = model.PhoneNumber, PhoneNumber = model.PhoneNumber, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; UserRepo.CreateUser(user, model.Password); if (user.Id != null) { // Add Customer Role UserRepo.AddUserRole(user.Id, StaticVariables.CustomerRoleId); // Add Customer var customer = new Core.Models.Customer() { UserId = user.Id, IsDeleted = false }; UserRepo.AddCustomer(customer); //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable Auth confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Auth", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your Auth", "Please confirm your Auth by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Login", "Auth")); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create(AddCustomerViewModel form, HttpPostedFileBase UserAvatar) { if (ModelState.IsValid) { #region Check for duplicate username or email if (form.UserName != null) { if (_usersRepo.UserNameExists(form.UserName)) { ViewBag.Message = "کاربر دیگری با همین نام کاربری در سیستم ثبت شده"; return(View(form)); } } if (_usersRepo.PhoneNumberExists(form.PhoneNumber)) { ViewBag.Message = "کاربر دیگری با همین شماره تلفن در سیستم ثبت شده"; return(View(form)); } if (_usersRepo.EmailExists(form.Email)) { ViewBag.Message = "کاربر دیگری با همین ایمیل در سیستم ثبت شده"; return(View(form)); } #endregion #region Upload Image if (UserAvatar != null) { var newFileName = Guid.NewGuid() + Path.GetExtension(UserAvatar.FileName); UserAvatar.SaveAs(Server.MapPath("/Files/UserAvatars/" + newFileName)); form.Avatar = newFileName; } #endregion var userModel = new User() { UserName = form.UserName, FirstName = form.FirstName, LastName = form.LastName, Email = form.Email, PhoneNumber = form.PhoneNumber, Avatar = form.Avatar }; userModel.UserName = form.UserName ?? form.PhoneNumber; _usersRepo.CreateUser(userModel, form.Password); _usersRepo.AddUserRole(userModel.Id, StaticVariables.CustomerRoleId); var customer = new Core.Models.Customer() { UserId = userModel.Id, IsDeleted = false, NationalCode = form.NationalCode, Address = form.Address, PostalCode = form.PostalCode, }; _repo.Add(customer); return(RedirectToAction("Index")); } return(View(form)); }
public Core.Models.Customer Post([FromBody] Core.Models.Customer customer) { return(caller.PostAsync <Core.Models.Customer>(configuration["ApiUrls:Customer"], customer).Result); }