public async Task <WebsiteUpdateModel> UpdateAsync(Guid id, WebsiteUpdateModel model) { if (id == Guid.Empty) { throw new ArgumentNullException(); } var website = await context.Websites.Include(w => w.Category) .Include(w => w.Login) .FirstOrDefaultAsync(w => w.Id.Equals(id)); if (website is null) { throw new NotFoundException("Website not found."); } if (!string.IsNullOrWhiteSpace(website.Name) && !website.Name.ToLower().Equals(model.Name.ToLower())) { await ValidateNameUniquenessAsync(model.Name); website.Name = model.Name; } if (!string.IsNullOrWhiteSpace(website.CategoryCode) && !website.CategoryCode.ToUpper().Equals(model.CategoryCode.ToUpper())) { website.CategoryId = await GetCategoryIdAsync(model.CategoryCode); } if (!string.IsNullOrWhiteSpace(model.URL)) { website.URL = model.URL; } if (!string.IsNullOrWhiteSpace(model.HomepageSnapshot)) { website.HomepageSnapshot = Convert.FromBase64String(model.HomepageSnapshot); } await context.SaveChangesAsync(); return(model); }
public async Task <IActionResult> PatchAsync(Guid id, [FromBody] WebsiteUpdateModel model) { var updated = await websiteService.UpdateAsync(id, model); return(Ok(updated)); }