Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
 public int?ApplyPriceOnReceipt(int productionPriceID, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (ProductionPriceMngEntities context = CreateContext())
         {
             int result = context.ProductionPriceMng_function_UpdatePriceReceivingNote(productionPriceID);
             return(result);
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(null);
     }
 }