public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var theme = await _themeDbContext.Themes.FindAsync(request.Id); if (theme == null) { throw new Exception("No record found .."); } _themeDbContext.Remove(theme); var success = await _themeDbContext.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem of deleting a record, please try it again later .."); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var theme = new Theme { Id = request.Id, CreatedAt = request.CreatedAt, Name = request.Name, DateForShown = request.DateForShown, IconImage = request.IconImage, MarqueeText = request.MarqueeText, PrimaryColor = request.PrimaryColor, SecondaryColor = request.SecondaryColor }; _themeDbContext.Themes.Add(theme); var success = await _themeDbContext.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem with saving chnages, please try it again later .."); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var theme = await _themeDbContext.Themes.FindAsync(request.Id); if (theme == null) { throw new Exception("No record can be found .."); } theme.Name = request.Name ?? theme.Name; theme.DateForShown = request.DateForShown ?? theme.DateForShown; theme.IconImage = request.IconImage ?? theme.IconImage; theme.MarqueeText = request.MarqueeText ?? theme.MarqueeText; theme.PrimaryColor = request.PrimaryColor ?? theme.PrimaryColor; theme.SecondaryColor = request.SecondaryColor ?? theme.SecondaryColor; var success = await _themeDbContext.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem of saving changes, please try it again later .."); }