Esempio n. 1
0
        public async Task <IActionResult> Edit(List <IFormFile> files, CustomerVM customerVM)
        {
            var fileNameDb = adamUnit.AttachmentRepository.SingleOrDefault(x =>
                                                                           x.OwnerId == customerVM.Id.ToString() && x.AttachmentOwner == AttachmentOwner.Customers);

            if (files.Count == 0 && fileNameDb == null)
            {
                ViewBag.ListCity = adamUnit.CityRepository.GetAll(x => x.Country == customerVM.Country).ToList();
                ViewBag.file     = "Please enter  image";
                return(View(customerVM));
            }
            var userDb = adamUnit.CustomerRepository.Find(customerVM.Id);

            if (userDb.Email != customerVM.Email)
            {
                if (adamUnit.CustomerRepository.Exists(x => x.Email == customerVM.Email))
                {
                    customerVM.FilePath =
                        adamUnit.AttachmentRepository.GetAll(x => x.OwnerId == customerVM.Id.ToString()).ToList();
                    ViewBag.ListCity = adamUnit.CityRepository.GetAll(x => x.Country == customerVM.Country).ToList();

                    ViewBag.Email = "Email is exists already";
                    return(View(customerVM));
                }
            }
            if (ModelState.IsValid)
            {
                var Cust = adamUnit.CustomerRepository.SingleOrDefault(x => x.Id == customerVM.Id && x.IsDeleted == false);
                await adamUnit.CustomerRepository.UpdateAsync(customerVM.ToModelEdit(Cust));

                string recordId = Cust.Id.ToString();
                if (files != null && files.Count > 0)
                {
                    string webRootPath = _hostingEnvironment.WebRootPath;
                    var    state       = adamUnit.AttachmentRepository.OnPostUpload(files, recordId,
                                                                                    AttachmentOwner.Customers, AttachmentType.Photo, webRootPath);
                }
                TempData["UpdateMessage"] = "Updated Successfully";
                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }