Пример #1
0
        public async Task <IActionResult> Post([FromBody] InventoryWeavingDocumentOutViewModel viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);

                InventoryWeavingDocument model = await Service.MapToModel(viewModel);


                await Service.Create(model);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                    .Ok();
                return(Created(String.Concat(Request.Path, "/", 0), Result));
            }
            catch (ServiceValidationExeption e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public void Validate_DefaultValue()
        {
            InventoryWeavingDocumentOutViewModel viewModel = ViewModel;
            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
        public void Validate_ADJOUT_Detail_AllQty_Null()
        {
            InventoryWeavingDocumentOutViewModel viewModel = ViewModel;

            viewModel.date    = DateTimeOffset.Now;
            viewModel.bonType = "ADJ KELUAR";
            foreach (var item in viewModel.items)
            {
                foreach (var detail in item.ListItems)
                {
                    detail.IsSave = true;
                }
            }

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
        public void Validate_ADJIN_Detail_Min()
        {
            InventoryWeavingDocumentOutViewModel viewModel = ViewModel;

            viewModel.date    = DateTimeOffset.Now;
            viewModel.bonType = "ADJ MASUK";
            foreach (var item in viewModel.items)
            {
                foreach (var detail in item.ListItems)
                {
                    detail.Qty      = -1;
                    detail.QtyPiece = -1;
                    detail.IsSave   = true;
                }
            }

            var result = viewModel.Validate(null);

            Assert.NotEmpty(result.ToList());
        }
Пример #5
0
        public async Task <InventoryWeavingDocument> MapToModel(InventoryWeavingDocumentOutViewModel data)
        {
            List <InventoryWeavingDocumentItem> DocsItems = new List <InventoryWeavingDocumentItem>();

            foreach (var i in data.items)
            {
                i.ListItems = i.ListItems.Where(s => s.IsSave).ToList();
                foreach (var d in i.ListItems)
                {
                    DocsItems.Add(new InventoryWeavingDocumentItem
                    {
                        Id                 = d.Id,
                        Active             = d.Active,
                        _CreatedBy         = d._CreatedBy,
                        _CreatedUtc        = d._CreatedUtc,
                        _CreatedAgent      = d._CreatedAgent,
                        _LastModifiedBy    = d._LastModifiedBy,
                        _LastModifiedUtc   = d._LastModifiedUtc,
                        _LastModifiedAgent = d._LastModifiedAgent,
                        _IsDeleted         = d._IsDeleted,
                        ProductOrderName   = i.ProductOrderNo,
                        ReferenceNo        = i.ReferenceNo,
                        Construction       = i.Construction,

                        Grade        = d.Grade,
                        Piece        = d.Piece == "BESAR" ? "1" : d.Piece == "KECIL"? "2" : "3",
                        MaterialName = d.MaterialName,
                        WovenType    = d.WovenType,
                        Width        = d.Width,
                        Yarn1        = d.Yarn1,
                        Yarn2        = d.Yarn2,
                        YarnType1    = d.YarnType1,
                        YarnType2    = d.YarnType2,
                        YarnOrigin1  = d.YarnOrigin1,
                        YarnOrigin2  = d.YarnOrigin2,

                        UomId         = 35,
                        UomUnit       = "MTR",
                        Quantity      = d.Qty,
                        QuantityPiece = d.QtyPiece,
                        ProductRemark = d.ProductRemark,
                        //InventoryWeavingDocumentId = d.InventoryWeavingDocumentId
                    });
                }
            }

            InventoryWeavingDocument model = new InventoryWeavingDocument
            {
                BonNo       = data.bonNo,
                BonType     = data.bonType,
                Date        = data.date,
                StorageId   = 105,
                StorageCode = "DNWDX2GZ",
                StorageName = "WEAVING 2 (EX. WEAVING 3) / WEAVING",
                Remark      = data.remark,
                Type        = "OUT",
                Items       = DocsItems
            };

            return(model);
        }