public HttpResponseMessage putItem(String id, Entities.MstItem item) { try { var items = from d in db.MstItems where d.Id == Convert.ToInt32(id) select d; if (items.Any()) { var userId = (from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d).FirstOrDefault().Id; var updateItems = items.FirstOrDefault(); updateItems.ItemCode = item.ItemCode; updateItems.BarCode = item.BarCode; updateItems.ItemDescription = item.ItemDescription; updateItems.Alias = item.Alias; updateItems.GenericName = item.GenericName; updateItems.Category = item.Category; updateItems.SalesAccountId = item.SalesAccountId; updateItems.AssetAccountId = item.AssetAccountId; updateItems.CostAccountId = item.CostAccountId; updateItems.InTaxId = item.InTaxId; updateItems.OutTaxId = item.OutTaxId; updateItems.UnitId = item.UnitId; updateItems.DefaultSupplierId = item.DefaultSupplierId; updateItems.Cost = item.Cost; updateItems.MarkUp = item.MarkUp; updateItems.Price = item.Price; updateItems.ImagePath = item.ImagePath; updateItems.ReorderQuantity = item.ReorderQuantity; updateItems.OnhandQuantity = item.OnhandQuantity; updateItems.IsInventory = item.IsInventory; updateItems.ExpiryDate = item.ExpiryDate; updateItems.LotNumber = item.LotNumber; updateItems.Remarks = item.Remarks; updateItems.EntryUserId = item.EntryUserId; updateItems.EntryDateTime = DateTime.Now; updateItems.UpdateUserId = item.UpdateUserId; updateItems.UpdateDateTime = DateTime.Now; updateItems.IsLocked = item.IsLocked; updateItems.DefaultKitchenReport = item.DefaultKitchenReport; updateItems.IsPackage = item.IsPackage; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 postItem(Entities.MstItem item) { try { var userId = (from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d).FirstOrDefault().Id; var accounts = from d in db.MstAccounts select d; var tax = from d in db.MstTaxes select d; var unit = from d in db.MstUnits select d; var supplier = from d in db.MstSuppliers select d; Data.MstItem newItem = new Data.MstItem(); newItem.ItemCode = "n/a"; newItem.BarCode = "n/a"; newItem.ItemDescription = "n/a"; newItem.Alias = "n/a"; newItem.GenericName = "n/a"; newItem.Category = "n/a"; newItem.SalesAccountId = accounts.Where(d => d.AccountType == "SALES").Select(d => d.Id).FirstOrDefault(); newItem.AssetAccountId = accounts.Where(d => d.AccountType == "ASSET").Select(d => d.Id).FirstOrDefault(); newItem.CostAccountId = accounts.Where(d => d.AccountType == "EXPENSES").Select(d => d.Id).FirstOrDefault(); newItem.InTaxId = tax.Select(d => d.Id).FirstOrDefault(); newItem.OutTaxId = tax.Select(d => d.Id).FirstOrDefault(); newItem.UnitId = unit.Select(d => d.Id).FirstOrDefault(); newItem.DefaultSupplierId = supplier.Select(d => d.Id).FirstOrDefault(); newItem.Cost = 0; newItem.MarkUp = 0; newItem.Price = 0; newItem.ImagePath = "n/a"; newItem.ReorderQuantity = 0; newItem.OnhandQuantity = 0; newItem.IsInventory = false; newItem.ExpiryDate = DateTime.Today; newItem.LotNumber = "n/a"; newItem.Remarks = "n/a"; newItem.EntryUserId = userId; newItem.EntryDateTime = DateTime.Today; newItem.UpdateUserId = userId; newItem.UpdateDateTime = DateTime.Today; newItem.IsLocked = false; newItem.DefaultKitchenReport = "n/a"; newItem.IsPackage = false; db.MstItems.InsertOnSubmit(newItem); db.SubmitChanges(); return(newItem.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }