public async Task <Dto.WebSite> Delete(long id) { var model = await this.unitOfWork.WebSites.GetById(id); Dbo.WebSite deletedWebsite = this.unitOfWork.WebSites.Delete(model); await this.unitOfWork.SaveChanges(); return(deletedWebsite.Map()); }
// can be with IMapper - no extention methods public static Dto.WebSite Map(this Dbo.WebSite webSite) { if (webSite == null) { return(null); } return(new Dto.WebSite() { Id = webSite.Id, Name = webSite.Name, Category = webSite.Category.Map(), Url = webSite.Url, SnapshotUrl = webSite.SnapshotUrl, LoginEmail = webSite.LoginEmail, LoginPassword = webSite.LoginPassword }); }
public async Task <Dto.WebSite> Create(Dto.WebSite website) { Validated.NotNull(website, nameof(website)); Dbo.Category category = await this.categoryService.GetByName(website.Category.Name); if (category == null) { category = await this.categoryService.Create(website.Category.Map()); } website.Category.Id = category.Id; Dbo.WebSite addedWebsite = this.unitOfWork.WebSites.Add(website.Map()); await this.unitOfWork.SaveChanges(); return(addedWebsite.Map()); }