public TimeTransactionViewModel Create([FromBody] TimeTransactionViewModel transaction) { if (!ModelState.IsValid) { throw new HttpApiException("Invalid Time Transaction Model"); } var entity = _timesheets.Create(new TimeTransaction { Active = transaction.Active, Visible = transaction.Visible, TransactionDate = transaction.TransactionDate, ProjectId = transaction.Project.IfNotNull(x => x.Id), EmployeeId = transaction.Employee.IfNotNull(x => x.Id), Time = transaction.Time, Comment = transaction.Comment }); return(AutoMapper.Mapper.Map <TimeTransactionViewModel>(entity)); //return GetById(entity.Id); // reload newly updated transaction to get all values }
public TimeTransactionViewModel Update([FromBody] TimeTransactionViewModel transaction) { if (!ModelState.IsValid) { throw new HttpApiException("Invalid Time Transaction Model"); } var entity = _timesheets.GetByID(transaction.Id); if (entity != null) { entity.Active = transaction.Active; entity.Visible = transaction.Visible; entity.TransactionDate = transaction.TransactionDate; entity.ProjectId = transaction.Project.IfNotNull(x => x.Id); entity.EmployeeId = transaction.Employee.IfNotNull(x => x.Id); entity.Time = transaction.Time; entity.Comment = transaction.Comment; entity = _timesheets.Update(entity); // entity => updated value } return(GetById(transaction.Id)); // reload newly updated transaction to get all values }