Exemplo n.º 1
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.º 2
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);
        }