示例#1
0
        public Int32 postItem()
        {
            try
            {
                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    = AccountId();
                newItem.AssetAccountId    = AccountId();
                newItem.CostAccountId     = AccountId();
                newItem.InTaxId           = TaxId();
                newItem.OutTaxId          = TaxId();
                newItem.UnitId            = UnitId();
                newItem.DefaultSupplierId = SupplierId();
                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)
            {
                return(0);
            }
        }
示例#2
0
        public HttpResponseMessage Post(Models.MstItem item)
        {
            try
            {
                var isLocked = true;
                var identityUserId = User.Identity.GetUserId();
                var mstUserId = 1;// (from d in db.MstUsers where "" + d.Id == identityUserId select d.Id).SingleOrDefault();
                var date = DateTime.Now;

                Data.MstItem newItem = new Data.MstItem();

                newItem.ItemCode = item.ItemCode != null ? item.ItemCode : "00000";
                newItem.BarCode = item.BarCode != null ? item.BarCode : "00000";
                newItem.ItemDescription = item.ItemDescription != null ? item.ItemDescription : "00000";
                newItem.Alias = item.Alias != null ? item.Alias : "00000";
                newItem.GenericName = item.GenericName != null ? item.GenericName : "00000";
                newItem.Category = item.Category != null ? item.Category : "00000";
                newItem.SalesAccountId = item.SalesAccountId != null ? item.SalesAccountId : 0;
                newItem.AssetAccountId = item.AssetAccountId != null ? item.AssetAccountId : 0;
                newItem.CostAccountId = item.CostAccountId != null ? item.CostAccountId : 0;
                newItem.InTaxId = item.InTaxId != null ? item.InTaxId : 0;
                newItem.OutTaxId = item.OutTaxId != null ? item.OutTaxId : 0;
                newItem.UnitId = item.UnitId != null ? item.UnitId : 0;
                newItem.DefaultSupplierId = item.DefaultSupplierId != null ? item.DefaultSupplierId : 0;
                newItem.Cost = item.Cost != null ? item.Cost : 0;
                newItem.MarkUp = item.MarkUp != null ? item.MarkUp : 0;
                newItem.Price = item.Price != null ? item.Price : 0;
                newItem.ImagePath = item.ImagePath != null ? item.ImagePath : "00000";
                newItem.ReorderQuantity = item.ReorderQuantity != null ? item.ReorderQuantity : 0;
                newItem.OnhandQuantity = item.OnhandQuantity != null ? item.OnhandQuantity : 0;
                newItem.IsInventory = item.IsInventory != null ? item.IsInventory : false;
                newItem.IsPackage = item.IsPackage != null ? item.IsPackage : false;
                newItem.EntryUserId = mstUserId;
                newItem.EntryDateTime = date;
                newItem.UpdateUserId = mstUserId;
                newItem.UpdateDateTime = date;
                newItem.IsLocked = isLocked != null ? isLocked : false;

                //ALLOW NULL
                newItem.ExpiryDate = date;
                newItem.LotNumber = item.LotNumber;
                newItem.Remarks = item.Remarks;
                newItem.DefaultKitchenReport = item.DefaultKitchenReport;

                db.MstItems.InsertOnSubmit(newItem);
                db.SubmitChanges();

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch(Exception 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);
            }
        }