public async Task <ServiceResponse <Anchor> > Update(Guid id, UpdateAnchorRequest request) { try { var anchor = await _anchorRepository.GetByIdInclusive(id, x => x.Include(w => w.ContactPerson).Include(s => s.Setting).Include(p => p.Address).ThenInclude(r => r.Region).ThenInclude(c => c.Country)); if (anchor == null) { return(new ServiceResponse <Anchor>($"The Requested Anchor Resource Could not be found")); } var updatedTime = DateTime.Now; anchor.Name = request.Name; anchor.Description = request.Description; anchor.LicenceNumber = request.LicenceNumber; anchor.RegistrationNumber = request.RegistrationNumber; anchor.DateOfRegistration = request.DateOfRegistration; anchor.LastUpdated = updatedTime; anchor.Setting.Name = request.SettingName; anchor.Setting.Description = request.SettingDescription; anchor.Setting.SaleOrderAutoApproval = request.SaleOrderAutoApproval; anchor.Setting.PurchaseOrderAutoApproval = request.PurchaseOrderAutoApproval; anchor.Setting.LastUpdated = updatedTime; anchor.ContactPerson.FirstName = request.FirstName; anchor.ContactPerson.LastName = request.LastName; anchor.ContactPerson.ContactPhone = request.ContactPhone; anchor.ContactPerson.ContactEmail = request.ContactEmail; anchor.Address.RegionId = request.RegionId; anchor.Address.PhoneNumber = request.AddressPhone; anchor.Address.Street = request.Street; anchor.Address.City = request.City; anchor.Address.EmailAddress = request.AddressEmail; await _anchorRepository.Update(id, anchor); return(new ServiceResponse <Anchor>(anchor)); } catch (Exception ex) { return(new ServiceResponse <Anchor>($"An Error Occured while updating anchor resource. {ex.Message}")); } }
public async Task <ActionResult> Edit(Guid id, EditAnchorViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (!id.Equals(request.AnchorId)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var updateAnchorRequest = new UpdateAnchorRequest { Id = request.AnchorId, Name = request.Name, Description = request.Description }; var result = await _anchorService.Update(id, updateAnchorRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Anchor Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }