public HttpResponseMessage Upsert(ItemViewModel item) { if (item.Id > 0) { var t = Update(item); return Request.CreateResponse(System.Net.HttpStatusCode.NoContent); } else { var t = Create(item); return Request.CreateResponse(t.ItemId); } }
private Item Create(ItemViewModel item) { Item t = new Item { ItemName = item.Name, ItemDescription = item.Description, AssignedUserId = item.AssignedUser, ModuleId = ActiveModule.ModuleID, CreatedByUserId = UserInfo.UserID, LastModifiedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.UtcNow, LastModifiedOnDate = DateTime.UtcNow }; _repository.AddItem(t); return t; }
public HttpResponseMessage Get(int itemId) { var item = new ItemViewModel(_repository.GetItem(itemId, ActiveModule.ModuleID)); return Request.CreateResponse(item); }
private Item Update(ItemViewModel item) { var t = _repository.GetItem(item.Id, ActiveModule.ModuleID); if (t != null) { t.ItemName = item.Name; t.ItemDescription = item.Description; t.AssignedUserId = item.AssignedUser; t.LastModifiedByUserId = UserInfo.UserID; t.LastModifiedOnDate = DateTime.UtcNow; } _repository.UpdateItem(t); return t; }