Exemplo n.º 1
0
        public ActionResult CopyProductItem(DocumentAndItemViewModel model)
        {
            var data = new MobileResponseModel();

            try
            {
                var document = GenericFactory.Business.GetDocument(model.DocumentId);
                var item     = document.DocumentProductItems.First(i => i.Id.ToString() == model.ItemId);
                var copyItem = new DocumentProductItem
                {
                    Id                         = Guid.NewGuid(),
                    DocumentId                 = item.DocumentId,
                    ProductId                  = item.ProductId,
                    ProductOptionId            = item.ProductOptionId,
                    ProductUnitId              = item.ProductUnitId,
                    Amount                     = item.Amount,
                    DiscountAmount             = item.DiscountAmount,
                    DiscountPercentage         = item.DiscountPercentage,
                    FromWarehouseId            = item.FromWarehouseId,
                    IsDeleted                  = false,
                    PricePerUnit               = item.PricePerUnit,
                    ProductItemPrintOptionals  = item.ProductItemPrintOptionals,
                    ProductItemScreenOptionals = item.ProductItemScreenOptionals,
                    ProductItemSewOptionals    = item.ProductItemSewOptionals,
                    TotalPrice                 = item.TotalPrice,
                };
                document.DocumentProductItems.Add(copyItem);
                GenericFactory.Business.UpdateDocument(document);
                data.Datas = new
                {
                    Id = document.Id.ToString()
                };
            }
            catch (Exception ex)
            {
                data.Status       = false;
                data.ErrorCode    = "001";
                data.ErrorMessage = ex.Message;
                data.MessageId    = "";
                data.TimeStamp    = "";
            }
            return(new JsonCamelCaseResult(data, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public static DocumentProductItem ToViewModel(this ProductAndOptionViewModel model)
        {
            var itemId = Guid.NewGuid();
            var item   = new DocumentProductItem
            {
                Id              = itemId,
                ProductId       = new System.Guid(model.ProductId),
                ProductUnitId   = new System.Guid(model.ProductUnitId),
                ProductOptionId = new System.Guid(model.ProductOptionId),
                Amount          = model.Amount,
                PricePerUnit    = (decimal)model.PricePerUnit,
                MaterialId      = new System.Guid(model.MaterialId)
            };
            var printOption1 = new ProductItemPrintOptional();
            var printOption2 = new ProductItemScreenOptional();
            var printOption3 = new ProductItemSewOptional();
            var printStatus  = (ItemOptionStatus)model.PrintOption.SelectedOption;

            switch (printStatus)
            {
            case ItemOptionStatus.ExistingPattern:
            {
                printOption1.Id = Guid.NewGuid();
                printOption1.OptionalStatusId = 1;
                printOption1.ProductItemId    = itemId;
                printOption1.PatternId        = new Guid(model.PrintOption.PatternId.ToString());
                break;
            }

            case ItemOptionStatus.NewPattern:
            {
                printOption1.Id = Guid.NewGuid();
                printOption1.OptionalStatusId = 2;
                printOption1.ColorCodeId      = new Guid(model.PrintOption.ColorId);
                printOption1.ProductItemId    = itemId;

                break;
            }

            case 0:
            {
                break;
            }
            }
            var screenStatus = (ItemOptionStatus)model.ScreenOption.SelectedOption;

            switch (screenStatus)
            {
            case ItemOptionStatus.ExistingPattern:
            {
                printOption2.Id = Guid.NewGuid();
                printOption2.OptionalStatusId = 1;
                printOption2.ProductItemId    = itemId;
                printOption2.PatternId        = new Guid(model.ScreenOption.PatternId.ToString());
                break;
            }

            case ItemOptionStatus.NewPattern:
            {
                printOption2.Id = Guid.NewGuid();
                printOption2.OptionalStatusId  = 2;
                printOption2.ColorCodeId       = new Guid(model.ScreenOption.ColorId);
                printOption2.PatternPositionId = new Guid(model.ScreenOption.ColorId);
                printOption2.ProductItemId     = itemId;

                break;
            }

            case 0:
            {
                break;
            }
            }
            var sewStatus = (ItemOptionStatus)model.SewOption.SelectedOption;

            switch (sewStatus)
            {
            case ItemOptionStatus.ExistingPattern:
            {
                printOption3.Id = Guid.NewGuid();
                printOption3.OptionalStatusId = 1;
                printOption3.ProductItemId    = itemId;
                printOption3.PatternId        = new Guid(model.SewOption.PatternId.ToString());
                break;
            }

            case ItemOptionStatus.NewPattern:
            {
                printOption3.Id = Guid.NewGuid();
                printOption3.OptionalStatusId  = 2;
                printOption3.PatternPositionId = new Guid(model.SewOption.PositionId);
                printOption3.ProductItemId     = itemId;
                printOption3.Remark            = model.SewOption.Remark;
                break;
            }

            case 0:
            {
                break;
            }
            }
            if (model.PrintOption.SelectedOption > 0)
            {
                item.ProductItemPrintOptionals.Add(printOption1);
            }
            if (model.ScreenOption.SelectedOption > 0)
            {
                item.ProductItemScreenOptionals.Add(printOption2);
            }
            if (model.SewOption.SelectedOption > 0)
            {
                item.ProductItemSewOptionals.Add(printOption3);
            }
            return(item);
        }
Exemplo n.º 3
0
        public static ProductItemViewModel ToViewModel(this DocumentProductItem entity)
        {
            var item = new ProductItemViewModel();

            item.ItemId          = entity.Id.ToString();
            item.ProductId       = entity.Product.Id.ToString();
            item.ProductName     = entity.Product.Name;
            item.ProductUnitId   = entity.ProductUnitId.ToString();
            item.ProductUnitName = entity.Unit.UnitName;
            item.Amount          = entity.Amount;
            item.PricePerUnit    = entity.PricePerUnit;
            var o1          = GenericFactory.Business.GetProductItemPrintOptionalByItemId(entity.Id.ToString());
            var printOption = new PrintOptionViewModel();

            if (o1 != null)
            {
                var pattern = GenericFactory.Business.GetPatternImageById(o1.PatternId.ToString());
                var path    = string.Format(@"../../../FileUpload/{0}",
                                            pattern.PatternImagePath.Replace(@"\", @"/")
                                            .Split(new string[] { @"FileUpload" }, StringSplitOptions.None)[1]
                                            .Remove(0, 1));
                var color = GenericFactory.Business.GetColorById(o1.ColorCodeId.ToString());
                printOption.Id               = o1.Id.ToString();
                printOption.PatternId        = pattern.Id.ToString();
                printOption.PatternName      = pattern.PatternName;
                printOption.PatternImagePath = path;
            }
            item.PrintOption = printOption;
            var o2           = GenericFactory.Business.GetProductItemScreenOptionalByItemId(entity.Id.ToString());
            var screenOption = new ScreenOptionViewModel();

            if (o2 != null)
            {
                var pattern = GenericFactory.Business.GetPatternImageById(o2.PatternId.ToString());
                var color   = GenericFactory.Business.GetColorById(o2.ColorCodeId.ToString());
                screenOption.Id = o2.Id.ToString();
                if (pattern != null)
                {
                    var path = string.Format(@"../../../FileUpload/{0}",
                                             pattern.PatternImagePath.Replace(@"\", @"/")
                                             .Split(new string[] { @"FileUpload" }, StringSplitOptions.None)[1]
                                             .Remove(0, 1));

                    screenOption.PatternId        = pattern.Id.ToString();
                    screenOption.PatternName      = pattern.PatternName;
                    screenOption.PatternImagePath = path;
                }
                if (o2.PatternPositionId != null)
                {
                    var position = GenericFactory.Business.GetPositionById(o2.PatternPositionId.ToString());
                    screenOption.PositionId   = position.Id.ToString();
                    screenOption.PositionName = position.PositionName;
                }
            }
            item.ScreenOption = screenOption;
            var o3        = GenericFactory.Business.GetProductItemSewOptionalByItemId(entity.Id.ToString());
            var sewOption = new SewOptionViewModel();

            if (o3 != null)
            {
                sewOption.Id = o3.Id.ToString();
                var pattern  = GenericFactory.Business.GetPatternImageById(o3.PatternId.ToString());
                var position = GenericFactory.Business.GetPositionById(o3.PatternPositionId.ToString());
                if (pattern != null)
                {
                    sewOption.PatternId   = pattern.Id.ToString();
                    sewOption.PatternName = pattern.PatternName;
                    var path = string.Format(@"../../../FileUpload/{0}",
                                             pattern.PatternImagePath.Replace(@"\", @"/")
                                             .Split(new string[] { @"FileUpload" }, StringSplitOptions.None)[1]
                                             .Remove(0, 1));
                    sewOption.PatternImagePath = path;
                }
                if (position != null)
                {
                    sewOption.PositionId   = position.Id.ToString();
                    sewOption.PositionName = position.PositionName;
                }
                sewOption.Remark = o3.Remark;
            }
            item.SewOption         = sewOption;
            item.ProductCategoryId = entity.Product.ProductCategoryId.ToString();
            item.ProductOptionId   = entity.ProductOptionId.ToString();
            item.MaterialId        = entity.MaterialId.ToString();
            return(item);
        }
Exemplo n.º 4
0
        public static Document ToEntity(this DocumentViewModel viewModel)
        {
            Guid _documentId = Guid.NewGuid();

            if (!string.IsNullOrEmpty(viewModel.Id))
            {
                _documentId = new System.Guid(viewModel.Id);
            }
            var document = new Document();

            document.Id = _documentId;
            document.BiddingStatusId = (int)BiddingStatus.Waiting;
            //document.ExpiryDate = DateTime.Parse(viewModel.ExpirationDate);
            document.UserId     = viewModel.SaleUserId;
            document.CustomerId = new System.Guid(viewModel.CustomerId);
            document.ContactId  = new System.Guid(viewModel.ContactId);
            document.PoNumber   = viewModel.PoNumber;
            //document.CustomerBranchId = new System.Guid(viewModel.CustomerBranchId);
            foreach (var i in viewModel.Items)
            {
                var itemId = Guid.NewGuid();
                var item   = new DocumentProductItem
                {
                    Id            = itemId,
                    ProductId     = new System.Guid(i.ProductId),
                    ProductUnitId = new System.Guid(i.ProductUnitId),
                    Amount        = i.Amount,
                    PricePerUnit  = (decimal)i.PricePerUnit
                };
                var printOption1 = new ProductItemPrintOptional();
                var printOption2 = new ProductItemScreenOptional();
                var printOption3 = new ProductItemSewOptional();
                var printStatus  = (ItemOptionStatus)i.PrintOption.SelectedOption;
                switch (printStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption1.Id = Guid.NewGuid();
                    printOption1.OptionalStatusId = 1;
                    printOption1.ProductItemId    = itemId;
                    printOption1.PatternId        = new Guid(i.PrintOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption1.Id = Guid.NewGuid();
                    printOption1.OptionalStatusId = 2;
                    printOption1.ColorCodeId      = new Guid(i.PrintOption.ColorId);
                    printOption1.ProductItemId    = itemId;

                    break;
                }

                case 0:
                {
                    break;
                }
                }
                var screenStatus = (ItemOptionStatus)i.ScreenOption.SelectedOption;
                switch (screenStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption2.Id = Guid.NewGuid();
                    printOption2.OptionalStatusId = 1;
                    printOption2.ProductItemId    = itemId;
                    printOption2.PatternId        = new Guid(i.ScreenOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption2.Id = Guid.NewGuid();
                    printOption2.OptionalStatusId  = 2;
                    printOption2.ColorCodeId       = new Guid(i.ScreenOption.ColorId);
                    printOption2.PatternPositionId = new Guid(i.ScreenOption.ColorId);
                    printOption2.ProductItemId     = itemId;

                    break;
                }

                case 0:
                {
                    break;
                }
                }
                var sewStatus = (ItemOptionStatus)i.SewOption.SelectedOption;
                switch (sewStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption3.Id = Guid.NewGuid();
                    printOption3.OptionalStatusId = 1;
                    printOption3.ProductItemId    = itemId;
                    printOption3.PatternId        = new Guid(i.SewOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption3.Id = Guid.NewGuid();
                    printOption3.OptionalStatusId  = 2;
                    printOption3.PatternPositionId = new Guid(i.SewOption.PositionId);
                    printOption3.ProductItemId     = itemId;
                    printOption3.Remark            = i.SewOption.Remark;
                    break;
                }

                case 0:
                {
                    break;
                }
                }
                if (i.PrintOption.SelectedOption > 0)
                {
                    item.ProductItemPrintOptionals.Add(printOption1);
                }
                if (i.ScreenOption.SelectedOption > 0)
                {
                    item.ProductItemScreenOptionals.Add(printOption2);
                }
                if (i.SewOption.SelectedOption > 0)
                {
                    item.ProductItemSewOptionals.Add(printOption3);
                }
                document.DocumentProductItems.Add(item);
            }
            //document.DeliveryContactId = new System.Guid(viewModel.DeliveryContactId);
            var delivery = new DocumentDelivery
            {
                Id         = Guid.NewGuid(),
                DocumentId = _documentId,
                Address1   = viewModel.DeliveryAddress
            };

            document.DocumentDeliveries.Add(delivery);
            document.RefPriceAndRemark  = viewModel.Remark;
            document.ConfirmedPriceDays = viewModel.ConfirmPriceDays;
            document.DeliveryDays       = viewModel.DeliveryDays;
            document.IsDelete           = false;
            return(document);
        }