Exemplo n.º 1
0
        public object ApproveData(int userID, System.Collections.Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            int getTypeID = (filters.ContainsKey("getTypeSearch") && filters["getTypeSearch"] != null && !string.IsNullOrEmpty(filters["getTypeSearch"].ToString().Trim())) ? Convert.ToInt32(filters["getTypeSearch"].ToString().Trim()) : 0;

            DTO.EditFormData data = new DTO.EditFormData(getTypeID);

            try
            {
                int id = (filters.ContainsKey("id") && filters["id"] != null && !string.IsNullOrEmpty(filters["id"].ToString().Trim())) ? Convert.ToInt32(filters["id"].ToString().Trim()) : 0;

                using (var context = CreateContext())
                {
                    if (getTypeID == 1)
                    {
                    }

                    if (getTypeID == 2)
                    {
                        ProductBreakDownPAL dbItem = context.ProductBreakDownPAL.FirstOrDefault(o => o.ProductBreakDownID == id);

                        if (dbItem == null)
                        {
                            notification.Type    = Library.DTO.NotificationType.Error;
                            notification.Message = "Can not find data!";
                            return(data);
                        }

                        dbItem.IsConfirmed   = true;
                        dbItem.ConfirmedBy   = userID;
                        dbItem.ConfirmedDate = DateTime.Now;

                        context.SaveChanges();

                        filters["id"] = dbItem.ProductBreakDownID;
                        return(GetData(userID, filters, out notification));
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }

            return(data);
        }
Exemplo n.º 2
0
        public void DTO2DB_ProductBreakDownPAL2(DTO.ProductBreakDownPALData dtoItem, ref ProductBreakDownPAL dbItem, string tempFile, int userId)
        {
            AutoMapper.Mapper.Map <DTO.ProductBreakDownPALData, ProductBreakDownPAL>(dtoItem, dbItem);

            foreach (var dbCategory in dbItem.ProductBreakDownCategoryPAL.ToArray())
            {
                if (!dtoItem.ProductBreakDownCategoryPAL.Select(o => o.ProductBreakDownCategoryID).Contains(dbCategory.ProductBreakDownCategoryID))
                {
                    foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImagePAL.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbCategoryImage.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbCategoryImage.FileUD);
                        }

                        dbCategory.ProductBreakDownCategoryImagePAL.Remove(dbCategoryImage);
                    }

                    foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryTypePAL.ToArray())
                    {
                        foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                        {
                            dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                        }

                        dbCategory.ProductBreakDownCategoryTypePAL.Remove(dbCategoryType);
                    }

                    dbItem.ProductBreakDownCategoryPAL.Remove(dbCategory);
                }
            }

            foreach (var dtoCategory in dtoItem.ProductBreakDownCategoryPAL)
            {
                if (string.IsNullOrEmpty(dtoCategory.ProductBreakDownCategoryNM))
                {
                    continue;
                }

                if (dtoCategory.ProductBreakDownCalculationTypeID == 1 && dtoCategory.UnitPrice == 0)
                {
                    continue;
                }

                ProductBreakDownCategoryPAL dbCategory;

                if (dtoCategory.ProductBreakDownCategoryID < 0)
                {
                    dbCategory = new ProductBreakDownCategoryPAL();
                    dbItem.ProductBreakDownCategoryPAL.Add(dbCategory);
                }
                else
                {
                    dbCategory = dbItem.ProductBreakDownCategoryPAL.FirstOrDefault(o => o.ProductBreakDownCategoryID == dtoCategory.ProductBreakDownCategoryID);
                }

                if (dbCategory != null)
                {
                    AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryPALData, ProductBreakDownCategoryPAL>(dtoCategory, dbCategory);

                    foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImagePAL.ToArray())
                    {
                        if (!dtoCategory.ProductBreakDownCategoryImagePAL.Select(o => o.ProductBreakDownCategoryImageID).Contains(dbCategoryImage.ProductBreakDownCategoryImageID))
                        {
                            if (!string.IsNullOrEmpty(dbCategoryImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbCategoryImage.FileUD);
                            }
                            dbCategory.ProductBreakDownCategoryImagePAL.Remove(dbCategoryImage);
                        }
                    }

                    foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryTypePAL.ToArray())
                    {
                        if (!dtoCategory.ProductBreakDownCategoryTypePAL.Select(o => o.ProductBreakDownCategoryTypeID).Contains(dbCategoryType.ProductBreakDownCategoryTypeID))
                        {
                            foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                            {
                                dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                            }

                            dbCategory.ProductBreakDownCategoryTypePAL.Remove(dbCategoryType);
                        }
                    }

                    foreach (var dtoCategoryImage in dtoCategory.ProductBreakDownCategoryImagePAL)
                    {
                        ProductBreakDownCategoryImagePAL dbCategoryImage;

                        if (dtoCategoryImage.ProductBreakDownCategoryImageID < 0)
                        {
                            dbCategoryImage = new ProductBreakDownCategoryImagePAL();
                            dbCategory.ProductBreakDownCategoryImagePAL.Add(dbCategoryImage);
                        }
                        else
                        {
                            dbCategoryImage = dbCategory.ProductBreakDownCategoryImagePAL.FirstOrDefault(o => o.ProductBreakDownCategoryImageID == dtoCategoryImage.ProductBreakDownCategoryImageID);
                        }

                        if (dbCategoryImage != null)
                        {
                            if (dtoCategoryImage.HasChange.HasValue && dtoCategoryImage.HasChange.Value)
                            {
                                dbCategoryImage.FileUD = fwFactory.CreateFilePointer(tempFile, dtoCategoryImage.NewFile, dtoCategoryImage.FileUD, dtoCategoryImage.FriendlyName);
                            }

                            AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryImagePALData, ProductBreakDownCategoryImagePAL>(dtoCategoryImage, dbCategoryImage);
                        }
                    }

                    foreach (var dtoCategoryType in dtoCategory.ProductBreakDownCategoryTypePAL)
                    {
                        ProductBreakDownCategoryTypePAL dbCategoryType;

                        if (dtoCategoryType.ProductBreakDownCategoryTypeID < 0)
                        {
                            dbCategoryType = new ProductBreakDownCategoryTypePAL();
                            dbCategory.ProductBreakDownCategoryTypePAL.Add(dbCategoryType);
                        }
                        else
                        {
                            dbCategoryType = dbCategory.ProductBreakDownCategoryTypePAL.FirstOrDefault(o => o.ProductBreakDownCategoryTypeID == dtoCategoryType.ProductBreakDownCategoryTypeID);
                        }

                        if (dbCategoryType != null)
                        {
                            AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryTypePALData, ProductBreakDownCategoryTypePAL>(dtoCategoryType, dbCategoryType);

                            foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                            {
                                if (!dtoCategoryType.ProductBreakDownDetailPAL.Select(s => s.ProductBreakDownDetailID).Contains(dbDetail.ProductBreakDownDetailID))
                                {
                                    dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                                }
                            }

                            foreach (var dtoDetail in dtoCategoryType.ProductBreakDownDetailPAL)
                            {
                                ProductBreakDownDetailPAL dbDetail;

                                if (dtoDetail.ProductBreakDownDetailID <= 0)
                                {
                                    dbDetail = new ProductBreakDownDetailPAL();
                                    dbCategoryType.ProductBreakDownDetailPAL.Add(dbDetail);
                                }
                                else
                                {
                                    dbDetail = dbCategoryType.ProductBreakDownDetailPAL.FirstOrDefault(o => o.ProductBreakDownDetailID == dtoDetail.ProductBreakDownDetailID);
                                }

                                if (dbDetail != null)
                                {
                                    AutoMapper.Mapper.Map <DTO.ProductBreakDownDetailPALData, ProductBreakDownDetailPAL>(dtoDetail, dbDetail);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public object UpdateData(int userID, System.Collections.Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            int getTypeID = (filters.ContainsKey("getTypeSearch") && filters["getTypeSearch"] != null && !string.IsNullOrEmpty(filters["getTypeSearch"].ToString().Trim())) ? Convert.ToInt32(filters["getTypeSearch"].ToString().Trim()) : 0;

            DTO.EditFormData data = new DTO.EditFormData(getTypeID);

            try
            {
                using (var context = CreateContext())
                {
                    if (getTypeID == 1)
                    {
                        int id = (filters.ContainsKey("id") && filters["id"] != null && !string.IsNullOrEmpty(filters["id"].ToString().Trim())) ? Convert.ToInt32(filters["id"].ToString().Trim()) : 0;
                        DTO.ProductBreakDownDefaultCategoryPALData dtoItem = ((Newtonsoft.Json.Linq.JObject)filters["dataView"]).ToObject <DTO.ProductBreakDownDefaultCategoryPALData>();

                        ProductBreakDownDefaultCategoryPAL dbItem;

                        if (id == 0)
                        {
                            dbItem = new ProductBreakDownDefaultCategoryPAL();
                            context.ProductBreakDownDefaultCategoryPAL.Add(dbItem);
                        }
                        else
                        {
                            dbItem = context.ProductBreakDownDefaultCategoryPAL.FirstOrDefault(o => o.ProductBreakDownDefaultCategoryID == id);
                        }

                        if (dbItem == null)
                        {
                            notification.Type    = Library.DTO.NotificationType.Error;
                            notification.Message = "Can not found data!";

                            return(data);
                        }

                        converter.DTO2DB_DefaultCategory(dtoItem, ref dbItem);

                        if (id == 0)
                        {
                            dbItem.CreatedBy   = userID;
                            dbItem.CreatedDate = DateTime.Now;
                        }

                        dbItem.UpdatedBy   = userID;
                        dbItem.UpdatedDate = DateTime.Now;

                        context.SaveChanges();

                        filters["id"] = dbItem.ProductBreakDownDefaultCategoryID;

                        return(GetData(userID, filters, out notification));
                    }

                    if (getTypeID == 2)
                    {
                        int id = (filters.ContainsKey("id") && filters["id"] != null && !string.IsNullOrEmpty(filters["id"].ToString().Trim())) ? Convert.ToInt32(filters["id"].ToString().Trim()) : 0;
                        DTO.ProductBreakDownPALData dtoItem = ((Newtonsoft.Json.Linq.JObject)filters["dataView"]).ToObject <DTO.ProductBreakDownPALData>();

                        ProductBreakDownPAL dbItem;

                        if (id == 0)
                        {
                            dbItem = new ProductBreakDownPAL();
                            context.ProductBreakDownPAL.Add(dbItem);
                        }
                        else
                        {
                            dbItem = context.ProductBreakDownPAL.FirstOrDefault(o => o.ProductBreakDownID == id);
                        }

                        if (dbItem == null)
                        {
                            notification.Type    = Library.DTO.NotificationType.Error;
                            notification.Message = "Can not find data";
                            return(null);
                        }

                        //convert data
                        converter.DTO2DB_ProductBreakDownPAL2(dtoItem, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userID.ToString() + @"\", userID);

                        //create product for model default option
                        var modelDefaultOption = dtoItem.ModelDefaultOption;
                        if (modelDefaultOption != null)
                        {
                            if (!modelDefaultOption.ProductID.HasValue) //create product incase not exist
                            {
                                if (!modelDefaultOption.ArticleCode.Contains("*"))
                                {
                                    Product dbProduct = new Product();
                                    context.Product.Add(dbProduct);
                                    dbItem.Product = dbProduct;

                                    dbProduct.ArticleCode          = modelDefaultOption.ArticleCode;
                                    dbProduct.Description          = modelDefaultOption.Description;
                                    dbProduct.ModelID              = modelDefaultOption.ModelID;
                                    dbProduct.FrameMaterialID      = modelDefaultOption.FrameMaterialID;
                                    dbProduct.FrameMaterialColorID = modelDefaultOption.FrameMaterialColorID;
                                    dbProduct.MaterialID           = modelDefaultOption.MaterialID;
                                    dbProduct.MaterialTypeID       = modelDefaultOption.MaterialTypeID;
                                    dbProduct.MaterialColorID      = modelDefaultOption.MaterialColorID;
                                    dbProduct.SubMaterialID        = modelDefaultOption.SubMaterialID;
                                    dbProduct.SubMaterialColorID   = modelDefaultOption.SubMaterialColorID;
                                    dbProduct.SeatCushionID        = modelDefaultOption.SeatCushionID;
                                    dbProduct.BackCushionID        = modelDefaultOption.BackCushionID;
                                    dbProduct.CushionColorID       = modelDefaultOption.CushionColorID;
                                    dbProduct.FSCTypeID            = modelDefaultOption.FSCTypeID;
                                    dbProduct.FSCPercentID         = modelDefaultOption.FSCPercentID;
                                }
                            }
                            else
                            {
                                dbItem.ProductID = modelDefaultOption.ProductID;
                            }
                        }

                        //tracking value
                        dbItem.UpdatedBy   = userID;
                        dbItem.UpdatedDate = DateTime.Now;
                        context.ProductBreakDownDetailPAL.Local.Where(o => o.ProductBreakDownCategoryTypePAL == null).ToList().ForEach(o => context.ProductBreakDownDetailPAL.Remove(o));
                        context.ProductBreakDownCategoryTypePAL.Local.Where(o => o.ProductBreakDownCategoryPAL == null).ToList().ForEach(o => context.ProductBreakDownCategoryTypePAL.Remove(o));
                        context.ProductBreakDownCategoryImagePAL.Local.Where(o => o.ProductBreakDownCategoryPAL == null).ToList().ForEach(o => context.ProductBreakDownCategoryImagePAL.Remove(o));
                        context.ProductBreakDownCategoryPAL.Local.Where(o => o.ProductBreakDownPAL == null).ToList().ForEach(o => context.ProductBreakDownCategoryPAL.Remove(o));

                        //save data
                        context.SaveChanges();

                        //reload data
                        filters["id"] = dbItem.ProductBreakDownID;
                        return(GetData(userID, filters, out notification));
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }

            return(data);
        }