示例#1
0
        public int Created(ProductionModel data)
        {
            try
            {

                if (data.ProductID == 0)
                {
                    var checkdata = _context.PRODUCTs.Where(x => x.ProductNameDesc == data.ProductNameDesc).ToList();
                    if (checkdata.Count() > 0)
                    {
                        return -1;
                    }

                    var new_data = new PRODUCT();
                    new_data.ProductNameDesc = data.ProductNameDesc;
                    new_data.ProductNameSort = data.ProductNameSort;
                    new_data.Color = data.Color ?? "";
                    new_data.Status = 1;
                    new_data.CreateBy = data.CreateBy ?? 0;
                    new_data.CreateDate = DateTime.Now;
                    new_data.UpdateBy = data.UpdateBy ?? 0;
                    new_data.UpdateDate = DateTime.Now;
                    new_data.Note = data.Note ?? "";

                    _context.Entry(new_data).State = EntityState.Added;
                    _context.SaveChanges();
                    var product_price = new PRODUCT_PRICE();
                    product_price.ProductID = new_data.ProductID;
                    product_price.CurrentPrice = data.CurrentPrice;
                    product_price.CreateBy = data.CreateBy ?? 0;
                    product_price.CreateDate = DateTime.Now;
                    product_price.UpdateBy = data.UpdateBy ?? 0;
                    product_price.UpdateDate = DateTime.Now;
                    product_price.Note = data.Note ?? "";
                    var result = CreatedProductPrice(product_price);
                    return result;

                }
                else
                {
                    var checkdata = _context.PRODUCTs.Where(x => x.ProductNameDesc == data.ProductNameDesc && x.ProductID != data.ProductID).ToList();
                    if (checkdata.Count() > 0)
                    {
                        return -1;
                    }
                    var old_data = _context.PRODUCTs.Find(data.ProductID);
                    if (old_data != null)
                    {
                        old_data.ProductNameDesc = data.ProductNameDesc;
                        old_data.ProductNameSort = data.ProductNameSort;
                        old_data.Color = data.Color ?? "";
                        old_data.Status = 1;
                        old_data.UpdateBy = data.UpdateBy ?? 0;
                        old_data.UpdateDate = DateTime.Now;
                        old_data.Note = data.Note ?? "";

                        _context.Entry(old_data).State = EntityState.Modified;
                        _context.SaveChanges();
                        var product_price = new PRODUCT_PRICE();
                        product_price.ProductID = data.ProductID;
                        product_price.CurrentPrice = data.CurrentPrice;
                        product_price.CreateBy = data.CreateBy ?? 0;
                        product_price.CreateDate = DateTime.Now;
                        product_price.UpdateBy = data.UpdateBy ?? 0;
                        product_price.UpdateDate = DateTime.Now;
                        product_price.Note = data.Note ?? "";
                        var result = CreatedProductPrice(product_price);
                        return result;
                    }
                    return 0;

                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
示例#2
0
 public int CreatedProductPrice(PRODUCT_PRICE product_price)
 {
     try
     {
         var data = _context.PRODUCT_PRICE.Where(x => x.ProductID == product_price.ProductID).SingleOrDefault();
         if (data != null)
         {
             data.WasPrice = data.CurrentPrice;
             data.CurrentPrice = product_price.CurrentPrice;
             data.Status = 1;
             data.UpdateBy = product_price.UpdateBy;
             data.UpdateDate = product_price.UpdateDate;
             data.CreateBy = product_price.CreateBy;
             data.CreateDate = product_price.CreateDate;
             data.Note = product_price.Note;
             data.Portions = "Regular";
             _context.Entry(data).State = EntityState.Modified;
             _context.SaveChanges();
             return 1;
         }
         else
         {
             var new_data = new PRODUCT_PRICE();
             new_data.ProductID = product_price.ProductID;
             new_data.WasPrice = 0;
             new_data.CurrentPrice = product_price.CurrentPrice;
             new_data.Status = 1;
             new_data.UpdateBy = product_price.UpdateBy;
             new_data.UpdateDate = product_price.UpdateDate;
             new_data.CreateBy = product_price.CreateBy;
             new_data.CreateDate = product_price.CreateDate;
             new_data.Note = product_price.Note;
             new_data.Portions = "Regular";
             _context.Entry(new_data).State = EntityState.Added;
             _context.SaveChanges();
             return 1;
         }
     }
     catch (Exception)
     {
         return 0;
     }
 }