public async Task<LandingResources> AddStylesAsync(LandingResources item) { var user = await _applicationDbContext.Users.FirstOrDefaultAsync(r => r.Id == item.AuthorId); if (user == null) return null; item.AuthorId = user.Id; var existingItem = await _applicationDbContext.LandingResources.FirstOrDefaultAsync(r => r.AuthorId == item.AuthorId); if (existingItem != null) { existingItem.Styles = item.Styles; _applicationDbContext.LandingResources.Attach(existingItem); _applicationDbContext.Entry(existingItem).Property(x => x.Styles).IsModified = true; await _applicationDbContext.SaveChangesAsync(); return existingItem; } _applicationDbContext.LandingResources.Add(item); await _applicationDbContext.SaveChangesAsync(); return item; }
public async Task<LandingResources> AddContentAsync(LandingResources item) { var user = await _applicationDbContext.Users.FirstOrDefaultAsync(r => r.Id == item.AuthorId); if (user == null) return null; item.AuthorId = user.Id; //var existingItem = await _applicationDbContext.LandingResources.FirstOrDefaultAsync(r => r.AuthorId == item.AuthorId); //if (existingItem != null) //{ // existingItem.Content = item.Content; // existingItem.LinkOnUbb = item.LinkOnUbb; // _applicationDbContext.LandingResources.Attach(existingItem); // _applicationDbContext.Entry(existingItem).Property(x => x.Content).IsModified = true; // _applicationDbContext.Entry(existingItem).Property(x => x.LinkOnUbb).IsModified = true; // await _applicationDbContext.SaveChangesAsync(); // return existingItem; //} _applicationDbContext.LandingResources.Add(item); await _applicationDbContext.SaveChangesAsync(); return item; }