public void DTO2DB_ProductInfo(DTO.ProductInfo.ProductDTO dtoItem, ref SampleProduct dbItem, string TmpFile)
        {
            AutoMapper.Mapper.Map <DTO.ProductInfo.ProductDTO, SampleProduct>(dtoItem, dbItem);

            // remark image
            foreach (SampleReferenceImage dbImage in dbItem.SampleReferenceImage.ToArray())
            {
                if (!dtoItem.ReferenceImageDTOs.Select(o => o.SampleReferenceImageID).Contains(dbImage.SampleReferenceImageID))
                {
                    // delete files
                    if (!string.IsNullOrEmpty(dbImage.FileUD))
                    {
                        fwFactory.RemoveImageFile(dbImage.FileUD);
                    }
                    dbItem.SampleReferenceImage.Remove(dbImage);
                }
            }
            foreach (DTO.ProductInfo.ReferenceImageDTO dtoImage in dtoItem.ReferenceImageDTOs)
            {
                SampleReferenceImage dbImage;
                if (dtoImage.SampleReferenceImageID <= 0)
                {
                    dbImage = new SampleReferenceImage();
                    dbItem.SampleReferenceImage.Add(dbImage);
                }
                else
                {
                    dbImage = dbItem.SampleReferenceImage.FirstOrDefault(o => o.SampleReferenceImageID == dtoImage.SampleReferenceImageID);
                }

                if (dbItem != null)
                {
                    AutoMapper.Mapper.Map <DTO.ProductInfo.ReferenceImageDTO, SampleReferenceImage>(dtoImage, dbImage);
                    if (!string.IsNullOrEmpty(dtoImage.BringInDate))
                    {
                        if (DateTime.TryParse(dtoImage.BringInDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate))
                        {
                            dbImage.BringInDate = tmpDate;
                        }
                    }
                    if (dtoImage.HasChanged && !string.IsNullOrEmpty(dtoImage.NewFile))
                    {
                        dbImage.FileUD = fwFactory.CreateFilePointer(TmpFile, dtoImage.NewFile, dbImage.FileUD);
                    }
                }
            }
        }
Example #2
0
        public bool UpdateProductInfoData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ProductInfo.ProductDTO dtoProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductInfo.ProductDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProduct dbItem;
                    if (id <= 0)
                    {
                        dbItem = new SampleProduct();
                        context.SampleProduct.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Sample Product not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_ProductInfo(dtoProduct, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\");
                        context.SaveChanges();
                    }

                    dtoItem = GetProductInfoData(dbItem.SampleProductID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Example #3
0
        public bool UpdateItemData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ItemData.ProductDTO dtoProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ItemData.ProductDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sample Product not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_ItemData(dtoProduct, ref dbItem);
                        context.SaveChanges();
                    }

                    dtoItem = GetItemData(dbItem.SampleProductID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
 public void DTO2DB_ItemData(DTO.ItemData.ProductDTO dtoItem, ref SampleProduct dbItem)
 {
     AutoMapper.Mapper.Map <DTO.ItemData.ProductDTO, SampleProduct>(dtoItem, dbItem);
 }
        public void DTO2DB_FactoryAssignment(DTO.FactoryAssignment.ProductDTO dtoItem, ref SampleProduct dbItem)
        {
            AutoMapper.Mapper.Map <DTO.FactoryAssignment.ProductDTO, SampleProduct>(dtoItem, dbItem);
            if (!string.IsNullOrEmpty(dtoItem.FactoryDeadline))
            {
                if (DateTime.TryParse(dtoItem.FactoryDeadline, nl, System.Globalization.DateTimeStyles.None, out tmpDate))
                {
                    dbItem.FactoryDeadline = tmpDate;
                }
            }

            // monitor
            foreach (SampleProductSubFactory dbSubFactory in dbItem.SampleProductSubFactory.ToArray())
            {
                if (!dtoItem.SubFactoryDTOs.Select(o => o.SampleProductSubFactoryID).Contains(dbSubFactory.SampleProductSubFactoryID))
                {
                    dbItem.SampleProductSubFactory.Remove(dbSubFactory);
                }
            }
            foreach (DTO.FactoryAssignment.SubFactoryDTO dtoSubFactory in dtoItem.SubFactoryDTOs)
            {
                SampleProductSubFactory dbSubFactory;
                if (dtoSubFactory.SampleProductSubFactoryID <= 0)
                {
                    dbSubFactory = new SampleProductSubFactory();
                    dbItem.SampleProductSubFactory.Add(dbSubFactory);
                }
                else
                {
                    dbSubFactory = dbItem.SampleProductSubFactory.FirstOrDefault(o => o.SampleProductSubFactoryID == dtoSubFactory.SampleProductSubFactoryID);
                }

                if (dbSubFactory != null)
                {
                    AutoMapper.Mapper.Map <DTO.FactoryAssignment.SubFactoryDTO, SampleProductSubFactory>(dtoSubFactory, dbSubFactory);
                }
            }
        }