示例#1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ProductionPriceDTO dtoProductionPrice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductionPriceDTO>();
            try
            {
                int?companyID = fw_factory.GetCompanyID(userId);
                using (ProductionPriceMngEntities context = CreateContext())
                {
                    ProductionPrice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ProductionPrice();
                        context.ProductionPrice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2DB_ProductionPrice(dtoProductionPrice, ref dbItem, userId, companyID);
                        //remove orphan
                        context.ProductionPriceDetail.Local.Where(o => o.ProductionPrice == null).ToList().ForEach(o => context.ProductionPriceDetail.Remove(o));

                        //save data
                        context.SaveChanges();

                        // Run automatic update unit price
                        if (dtoProductionPrice.UpdateTypeID.HasValue && dtoProductionPrice.UpdateTypeID.Value == 2)
                        {
                            context.ProductionPriceMng_function_UpdatePriceReceivingNote(dbItem.ProductionPriceID);
                        }

                        //get return data
                        dtoItem = GetData(dbItem.ProductionPriceID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception iEx = Library.Helper.GetInnerException(ex);
                notification.Type    = NotificationType.Error;
                notification.Message = iEx.Message;
                return(false);
            }
        }
示例#2
0
 private bool SaveDataBeforeLock(int userId, int id, DTO.ProductionPriceDTO dtoProductionPrice, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         int?companyID = fw_factory.GetCompanyID(userId);
         using (ProductionPriceMngEntities context = CreateContext())
         {
             ProductionPrice dbItem = null;
             if (id == 0)
             {
                 dbItem = new ProductionPrice();
                 context.ProductionPrice.Add(dbItem);
             }
             else
             {
                 dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
             }
             if (dbItem == null)
             {
                 notification.Message = "data not found!";
                 return(false);
             }
             else
             {
                 //convert dto to db
                 converter.DTO2DB_ProductionPrice(dtoProductionPrice, ref dbItem, userId, companyID);
                 //remove orphan
                 context.ProductionPriceDetail.Local.Where(o => o.ProductionPrice == null).ToList().ForEach(o => context.ProductionPriceDetail.Remove(o));
                 //save data
                 context.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(false);
     }
 }
示例#3
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (ProductionPriceMngEntities context = CreateContext())
         {
             var dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
             context.ProductionPrice.Remove(dbItem);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(false);
     }
 }