public async Task <CsCommandForAdminSection> Add(CsCommandForAdminSection cmd) { var userId = Resolve <ICurrentUserContext>().Id; var cmdDbEntity = new CsCommand { UserId = userId, Name = cmd.Name, Code = cmd.Code, AddedAt = DateTime.Now }; Db.Add(cmdDbEntity); await Db.SaveChangesAsync(); return(new CsCommandForAdminSection { Id = cmdDbEntity.Id, Name = cmdDbEntity.Name, Code = cmdDbEntity.Code }); }
public async Task Update(CsCommandForAdminSection cmd) { var userId = Resolve <ICurrentUserContext>().Id; var cmdFromDb = await Query <CsCommand>() .FirstOrDefaultAsync(c => c.Id == cmd.Id); if (cmdFromDb == null) { throw new ApplicationException("Command not found."); } if (cmdFromDb.UserId != userId) { throw new ApplicationException("Trying to update other user's command."); } cmdFromDb.Name = cmd.Name; cmdFromDb.Code = cmd.Code; Db.Update(cmdFromDb); await Db.SaveChangesAsync(); }
public Task Put(CsCommandForAdminSection cmd) => Resolve <AdminService>().Update(cmd);
public Task <CsCommandForAdminSection> Post(CsCommandForAdminSection cmd) => Resolve <AdminService>().Add(cmd);