Ejemplo n.º 1
0
        public ActionResult ProfileEdit(ProfileViewModel model)
        {
            var user           = _unitOfWork.GetRepo <Customer>().GetObject(x => x.Email == User.Identity.Name);
            var IsEmailChanged = model.Customer.Email != user.Email;

            user.Name           = model.Customer.Name;
            user.Surname        = model.Customer.Surname;
            user.Email          = model.Customer.Email;
            user.DateOfBirth    = model.Customer.DateOfBirth;
            user.BillingAddress =
                _unitOfWork.GetRepo <Address>().GetObject(x => x.Id == model.Customer.BillingAddress.Id);
            user.ShippingAddress = _unitOfWork.GetRepo <Address>().GetObject(x => x.Id == model.Customer.ShippingAddress.Id);
            var validator = new ProfilUpdateValidator(_unitOfWork).Validate(user);

            if (validator.IsValid)
            {
                _unitOfWork.GetRepo <Customer>().Update(user);
            }
            var isSuccess = _unitOfWork.Commit();

            TempData["IsSuccess"] = isSuccess;
            validator.Errors.ToList().ForEach(a =>
            {
                ModelState.AddModelError("Customer." + a.PropertyName, a.ErrorMessage);
            });
            TempData["ModelState"] = ModelState;
            TempData["Message"]    = isSuccess ? "Kullanıcı bilgileri güncelleme işlemi başarılı bir şekilde gerçekleştirildi." : "Kullanıcı bilgileri güncelleme işlemi gerçekleştirilemedi lütfen tekrar deneyiniz.";
            if (IsEmailChanged && isSuccess)
            {
                FormsAuthentication.SignOut();
                TempData["Message"] = "Güncelleme işlemi başarıyla gerçekleştirildi.Email adresinizi değiştirdiğiniz için tekrar giriş yapmanız gerekmektedir.";
                return(RedirectToAction("SignIn"));
            }
            return(RedirectToAction("MyAccount"));
        }
Ejemplo n.º 2
0
        public ActionResult ProfileEdit(ProfileEditViewModel model)
        {
            var validator            = new ProfilUpdateValidator(_unitOfWork).Validate(model.CustomerPicture.Customer);
            var modelCustomerPicture = _unitOfWork.GetRepo <CustomerPicture>().Where(x => x.Customer.Email == HttpContext.User.Identity.Name).FirstOrDefault();
            var isEmailChange        = modelCustomerPicture.Customer.Email != model.CustomerPicture.Customer.Email;

            if (validator.IsValid)
            {
                if (modelCustomerPicture != null)
                {
                    modelCustomerPicture.Customer.Name    = model.CustomerPicture.Customer.Name;
                    modelCustomerPicture.Customer.Surname = model.CustomerPicture.Customer.Surname;
                    modelCustomerPicture.Customer.Email   = model.CustomerPicture.Customer.Email;
                    _unitOfWork.GetRepo <CustomerPicture>().Update(modelCustomerPicture);
                }
            }

            var isSuccess = _unitOfWork.Commit();

            ViewBag.IsSuccess = isSuccess;
            ViewBag.Message   = isSuccess ? "Profil güncelleme işlemi başarılı bir şekilde gerçekleştirildi." : "Profil güncelleme işlemi gerçekleştirilemedi lütfen tekrar deneyiniz.";
            validator.Errors.ToList().ForEach(a =>
            {
                ModelState.AddModelError("CustomerPicture.Customer." + a.PropertyName, a.ErrorMessage);
            });
            model.CustomerPicture = modelCustomerPicture;
            if (!isSuccess || !isEmailChange)
            {
                return(View(model));
            }
            TempData["isEmailChange"] = true;
            TempData["EmailChange"]   = "Email Bilgilerinizdeki Değişiklik Sebebiyle Tekrar Giriş Yapmanız Gerekmektedir.";
            FormsAuthentication.SignOut();
            return(RedirectToAction("Login", "Account"));
        }