public async Task <IActionResult> UpdateProfile()
        {
            var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

            CustomerProfile loggedProfile = _profileRepo.GetSingle(cProfile => cProfile.UserId == loggedUser.Id);

            UpdateCustomerProfileViewModel vm = new UpdateCustomerProfileViewModel
            {
                UserId  = loggedUser.Id,
                Email   = loggedUser.Email,
                ImgPath = "admin\\person-solid.png"
            };

            if (loggedProfile != null)
            {
                vm.FirstName = loggedProfile.FirstName;
                vm.LastName  = loggedProfile.LastName;
                vm.Email     = loggedProfile.Email;
                vm.Mobile    = loggedProfile.Mobile;

                if (loggedProfile.ImgPath != null)
                {
                    vm.ImgPath = loggedProfile.ImgPath;
                }
            }

            return(View(vm));
        }
Exemple #2
0
        public ActionResult UpdateCustomerProfile(int userId)
        {
            using (var db = new TourEntities())
            {
                var customer = db.User_Customer_Adgent.Where(x => x.UserId == userId).FirstOrDefault();

                UpdateCustomerProfileViewModel customerViewModel = new UpdateCustomerProfileViewModel();

                customerViewModel.NRIC              = customer.NRIC;
                customerViewModel.CustomerId        = customer.CustomerId;
                customerViewModel.CustomerName      = customer.CustomerName;
                customerViewModel.EmailAddress      = customer.EmailAddress;
                customerViewModel.BankAccountNumber = customer.BankAccountNumber;
                customerViewModel.BankName          = customer.BankName;
                customerViewModel.PhoneNumber       = customer.PhoneNumber;
                customerViewModel.Address           = customer.Address;
                customerViewModel.DateOfBirth       = customer.DateOfBirth;
                customerViewModel.CustomerCode      = customer.CustomerCode;
                customerViewModel.RenewDate         = customer.RenewDate;
                customerViewModel.ExpiredDate       = customer.ExpiredDate;
                customerViewModel.AvailableAmount   = customer.AvailableAmount;
                customerViewModel.AvailablePoint    = customer.AvailablePoint;
                customerViewModel.AvailableTVR      = customer.AvailableTVR;
                customerViewModel.AgentCode         = customer.AgentCode;
                customerViewModel.AgentName         = customer.AgentName;
                customerViewModel.IntroducerCode    = customer.IntroduceCode;
                customerViewModel.IntroducerName    = customer.IntroduceName;


                return(View(customerViewModel));
            }
        }
        public async Task <IActionResult> UpdateProfile(UpdateCustomerProfileViewModel vm, IFormFile ImgPath)
        {
            if (ModelState.IsValid)
            {
                var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name);

                CustomerProfile loggedProfile = _profileRepo.GetSingle(p => p.UserId == loggedUser.Id);

                string uploadPath = Path.Combine(_environment.WebRootPath, "Uploads");
                uploadPath = Path.Combine(uploadPath, User.Identity.Name);
                Directory.CreateDirectory(Path.Combine(uploadPath, "Profile"));

                if (ImgPath != null)
                {
                    string fileName = Path.GetFileName(ImgPath.FileName);

                    using (FileStream fs = new FileStream(Path.Combine(uploadPath, "Profile", fileName), FileMode.Create))
                    {
                        ImgPath.CopyTo(fs);
                    }

                    vm.ImgPath = Path.Combine(User.Identity.Name, "Profile", fileName);
                }

                if (loggedProfile != null)
                {
                    loggedProfile.FirstName = vm.FirstName;
                    loggedProfile.LastName  = vm.LastName;
                    loggedProfile.Email     = vm.Email;
                    loggedProfile.Mobile    = vm.Mobile;
                    loggedProfile.ImgPath   = vm.ImgPath;

                    _profileRepo.Update(loggedProfile);
                }
                else
                {
                    loggedProfile = new CustomerProfile();

                    loggedProfile.FirstName = vm.FirstName;
                    loggedProfile.LastName  = vm.LastName;
                    loggedProfile.Email     = vm.Email;
                    loggedProfile.Mobile    = vm.Mobile;
                    loggedProfile.UserId    = loggedUser.Id;
                    loggedProfile.ImgPath   = vm.ImgPath;

                    _profileRepo.Create(loggedProfile);
                }
            }

            return(RedirectToAction("Index", "Customer"));
        }
Exemple #4
0
        public JsonResult UpdateCustomerProfile(UpdateCustomerProfileViewModel model)
        {
            using (var db = new TourEntities())
            {
                var userWithNRIC = db.Customer.Where(x => x.NRIC == model.NRIC && x.CustomerId != model.CustomerId).FirstOrDefault();

                if (userWithNRIC != null)
                {
                    ModelState.AddModelError("NRIC", "NRIC Duplication");
                }

                if (ModelState.IsValid)
                {
                    var customer = db.Customer.Where(x => x.CustomerId == model.CustomerId).FirstOrDefault();

                    customer.CustomerName      = model.CustomerName;
                    customer.NRIC              = model.NRIC;
                    customer.PhoneNumber       = model.PhoneNumber;
                    customer.Address           = model.Address;
                    customer.BankAccountNumber = model.BankAccountNumber;
                    customer.BankName          = model.BankName;
                    customer.DateOfBirth       = model.DateOfBirth;

                    var user = db.User.Where(x => x.UserId == customer.UserId).FirstOrDefault();
                    user.EmailAddress = model.EmailAddress;

                    db.SaveChanges();


                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <string> errors = new List <string>();

                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                        }
                    }
                    return(Json(new { success = false, issue = model, errors = errors }, JsonRequestBehavior.AllowGet));
                }
            }
        }