Example #1
0
        public bool UpdatePurchasingPrice(int userId, object dtoItems, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            if (!fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_WEX_VVP))
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = "You dont have access to this VVP data!";
                return(false);
            }


            List <DTO.PriceDTO> dataItems = ((Newtonsoft.Json.Linq.JArray)dtoItems).ToObject <List <DTO.PriceDTO> >();

            try
            {
                using (var context = CreateContext())
                {
                    foreach (DTO.PriceDTO pItem in dataItems)
                    {
                        ProductPurchasingPrice pPrice = context.ProductPurchasingPrice.FirstOrDefault(o => o.ProductID == pItem.ProductID);
                        if (pPrice != null)
                        {
                            pPrice.PurchasingPrice = pItem.Price;
                        }
                        //else
                        //{
                        //    pPrice = new ProductPurchasingPrice();
                        //    context.ProductPurchasingPrice.Add(pPrice);

                        //    pPrice.PurchasingPrice = pItem.Price;
                        //}
                    }
                    context.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(false);
            }
        }
Example #2
0
        public bool UpdateValueObsolescence(int userId, object dtoItems, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            List <DTO.ValueObsolescenceDTO> dataItems = ((Newtonsoft.Json.Linq.JArray)dtoItems).ToObject <List <DTO.ValueObsolescenceDTO> >();

            try
            {
                using (var context = CreateContext())
                {
                    foreach (DTO.ValueObsolescenceDTO dtoItem in dataItems)
                    {
                        ProductPurchasingPrice dbItem = context.ProductPurchasingPrice.FirstOrDefault(o => o.ProductID == dtoItem.ProductID);
                        if (dbItem != null)
                        {
                            dbItem.ValueObsolescence = dtoItem.ValueObsolescence;
                        }
                        else
                        {
                            ProductPurchasingPrice pItem = new ProductPurchasingPrice();
                            context.ProductPurchasingPrice.Add(pItem);
                            pItem.ProductID         = dtoItem.ProductID;
                            pItem.ValueObsolescence = dtoItem.ValueObsolescence;
                        }
                    }
                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(false);
            }
        }