Ejemplo n.º 1
0
        public async Task <IActionResult> EditAsync(EditRequestViewModel model)
        {
            if (ModelState.IsValid)
            {
                ServiceRequest serviceRequest = await _oDServiceRequestRepository.GetServiceRequestIdAsync(model.ServiceRequestId);

                serviceRequest.ApplicantName   = model.FullName;
                serviceRequest.ApplicationDate = DateTime.Now;

                //make all application pending after editing
                serviceRequest.Status        = "Pending";
                serviceRequest.RejectMessage = null;
                serviceRequest.Location      = model.Location;

                if (model.Image != null)
                {
                    if (model.ExistingImageURL != null)
                    {
                        string filePath = Path.Combine(_webHostEnvironment.WebRootPath + model.ExistingImageURL);
                        System.IO.File.Delete(filePath);
                    }

                    serviceRequest.ImageUrl = ProcessUploadedImage(model.Image);
                }

                await _oDServiceRequestRepository.UpdateRequestAsync(serviceRequest);

                return(RedirectToAction("MyRequests", new { applicantId = serviceRequest.ApplicantId }));
            }
            return(View());
        }