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 async Task <InventoryWeavingDocument> GetTestData() { InventoryWeavingDocument invWDoc = GetNewData(); await Service.Create(invWDoc); return(invWDoc); }
public async Task Create(InventoryWeavingDocument model) { //var bonCheck = this.DbSetDoc.FirstOrDefault(s => s.Date.Date == model.Date.Date && s.BonType == model.BonType && s.Type == "OUT"); // var bonCheck = this.DbContext.InventoryWeavingDocuments.Where(s => s.Date.Date == model.Date.Date && s.BonType == model.BonType && s.Type == "OUT").FirstOrDefault(); // if (bonCheck == null) //{ model.BonNo = GenerateBon(model.BonType, model.Date); model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSetDoc.Add(model); var result = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { InventoryWeavingMovement movement = new InventoryWeavingMovement { ProductOrderName = item.ProductOrderName, BonNo = model.BonNo, ReferenceNo = item.ReferenceNo, Construction = item.Construction, Grade = item.Grade, //Piece = item.Piece, MaterialName = item.MaterialName, WovenType = item.WovenType, Width = item.Width, Yarn1 = item.Yarn1, Yarn2 = item.Yarn2, YarnType1 = item.YarnType1, YarnType2 = item.YarnType2, YarnOrigin1 = item.YarnOrigin1, YarnOrigin2 = item.YarnOrigin2, UomId = item.UomId, UomUnit = item.UomUnit, Quantity = item.Quantity, QuantityPiece = item.QuantityPiece, ProductRemark = item.ProductRemark, Type = model.Type, InventoryWeavingDocumentId = model.Id, InventoryWeavingDocumentItemId = item.Id }; movement.FlagForCreate(IdentityService.Username, UserAgent); movement.FlagForUpdate(IdentityService.Username, UserAgent); DbSetMovement.Add(movement); } var result2 = await DbContext.SaveChangesAsync(); }
public async Task UploadData(InventoryWeavingDocument data, string username) { //IInventoryWeavingMovementService movement = ServiceProvider.GetService<IInventoryWeavingMovementService>(); foreach (var i in data.Items) { MoonlayEntityExtension.FlagForCreate(i, username, USER_AGENT); MoonlayEntityExtension.FlagForUpdate(i, username, USER_AGENT); } MoonlayEntityExtension.FlagForCreate(data, username, USER_AGENT); MoonlayEntityExtension.FlagForUpdate(data, username, USER_AGENT); DbSet.Add(data); var result = await DbContext.SaveChangesAsync(); foreach (var item in data.Items) { InventoryWeavingMovement movementModel = new InventoryWeavingMovement { ProductOrderName = item.ProductOrderName, BonNo = data.BonNo, ReferenceNo = item.ReferenceNo, Construction = item.Construction, Grade = item.Grade, //Piece = item.Piece, MaterialName = item.MaterialName, WovenType = item.WovenType, Width = item.Width, Yarn1 = item.Yarn1, Yarn2 = item.Yarn2, YarnType1 = item.YarnType1, YarnType2 = item.YarnType2, YarnOrigin1 = item.YarnOrigin1, YarnOrigin2 = item.YarnOrigin2, UomId = item.UomId, UomUnit = item.UomUnit, Quantity = item.Quantity, QuantityPiece = item.QuantityPiece, ProductRemark = item.ProductRemark, Type = data.Type, InventoryWeavingDocumentId = data.Id, InventoryWeavingDocumentItemId = item.Id, Barcode = item.Barcode, ProductionOrderDate = item.ProductionOrderDate, DestinationArea = item.DestinationArea //await BulkInsert(data, username); }; MoonlayEntityExtension.FlagForCreate(movementModel, username, USER_AGENT); MoonlayEntityExtension.FlagForUpdate(movementModel, username, USER_AGENT); DbSet2.Add(movementModel); } var result2 = await DbContext.SaveChangesAsync(); }
public async Task <InventoryWeavingDocument> MapToModel(InventoryWeavingDocumentViewModel data) { InventoryWeavingDocument model = new InventoryWeavingDocument { BonNo = data.bonNo, BonType = data.bonType, Date = data.date, StorageId = data.storageId, StorageCode = data.storageCode, StorageName = data.storageName, Remark = data.remark, Type = data.type, Items = data.items.Select(item => new InventoryWeavingDocumentItem() { Id = item.Id, Active = item.Active, _CreatedBy = item._CreatedBy, _CreatedUtc = item._CreatedUtc, _CreatedAgent = item._CreatedAgent, _LastModifiedBy = item._LastModifiedBy, _LastModifiedUtc = item._LastModifiedUtc, _LastModifiedAgent = item._LastModifiedAgent, _IsDeleted = item._IsDeleted, ProductOrderName = item.productOrderNo, ReferenceNo = item.referenceNo, Construction = item.construction, Grade = item.grade, // Piece = item.piece, MaterialName = item.materialName, WovenType = item.wovenType, Width = item.width, Yarn1 = item.yarn1, Yarn2 = item.yarn2, YarnType1 = item.yarnType1, YarnType2 = item.yarnType2, YarnOrigin1 = item.yarnOrigin1, YarnOrigin2 = item.yarnOrigin2, UomId = item.uomId, UomUnit = item.uomUnit, Quantity = item.quantity, QuantityPiece = item.quantityPiece, ProductRemark = item.productRemark, InventoryWeavingDocumentId = item.InventoryWeavingDocumentId, Barcode = item.barcode, ProductionOrderDate = item.productionOrderDate, DestinationArea = data.bonType, Type = "IN" }).ToList() }; return(model); }
public InventoryWeavingDocument CopyData(InventoryWeavingDocument oldData) { InventoryWeavingDocument newData = new InventoryWeavingDocument(); PropertyCopier <InventoryWeavingDocument, InventoryWeavingDocument> .Copy(oldData, newData); newData.Items = new List <InventoryWeavingDocumentItem>(); foreach (var oldItem in oldData.Items) { InventoryWeavingDocumentItem newItem = new InventoryWeavingDocumentItem(); PropertyCopier <InventoryWeavingDocumentItem, InventoryWeavingDocumentItem> .Copy(oldItem, newItem); newData.Items.Add(newItem); } return(newData); }
public async Task <int> Create(InventoryWeavingDocument model) { int Created = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { model.FlagForCreate(IdentityService.Username, USER_AGENT); model.FlagForUpdate(IdentityService.Username, USER_AGENT); DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); } catch (Exception e) { transaction.Rollback(); throw new Exception("Insert Error : " + e.Message); } } return(Created); }
public virtual async Task <IActionResult> Put([FromRoute] int id, [FromBody] InventoryWeavingDocumentDetailViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); if (id != viewModel.Id) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(); return(BadRequest(Result)); } InventoryWeavingDocument model = await service.MapToModelUpdate(viewModel); await service.UpdateAsync(id, model); return(NoContent()); } 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 async Task <IActionResult> PostCSVFileAsync(string source, DateTime date) // public async Task<IActionResult> PostCSVFileAsync(double source, double destination, DateTime date) { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; identityService.Token = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", ""); identityService.TimezoneOffset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); if (Request.Form.Files.Count > 0) { //VerifyUser(); var UploadedFile = Request.Form.Files[0]; StreamReader Reader = new StreamReader(UploadedFile.OpenReadStream()); List <string> FileHeader = new List <string>(Reader.ReadLine().Split(",")); var ValidHeader = service.CsvHeader.SequenceEqual(FileHeader, StringComparer.OrdinalIgnoreCase); if (ValidHeader) { Reader.DiscardBufferedData(); Reader.BaseStream.Seek(0, SeekOrigin.Begin); Reader.BaseStream.Position = 0; CsvReader Csv = new CsvReader(Reader); Csv.Configuration.IgnoreQuotes = false; Csv.Configuration.Delimiter = ","; Csv.Configuration.RegisterClassMap <InventoryWeavingDocumentMap>(); Csv.Configuration.HeaderValidated = null; List <InventoryWeavingDocumentCsvViewModel> Data = Csv.GetRecords <InventoryWeavingDocumentCsvViewModel>().ToList(); InventoryWeavingDocumentViewModel Data1 = await service.MapToViewModel(Data, date, source); //InventoryWeavingDocumentViewModel Data1 = await service.MapToViewModel(Data, source); ValidateService.Validate(Data1); Tuple <bool, List <object> > Validated = service.UploadValidate(ref Data, Request.Form.ToList()); Reader.Close(); if (Validated.Item1) { var CheckNota = service.checkNota(Data); if (CheckNota == 0) { InventoryWeavingDocument data = await service.MapToModel(Data1); await service.UploadData(data, identityService.Username); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(HttpContext.Request.Path, Result)); } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, "Nota Sudah Pernah di Input").Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } } else { using (MemoryStream memoryStream = new MemoryStream()) { using (StreamWriter streamWriter = new StreamWriter(memoryStream)) using (CsvWriter csvWriter = new CsvWriter(streamWriter)) { csvWriter.WriteRecords(Validated.Item2); } return(File(memoryStream.ToArray(), ContentType, FileName)); } } } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, General.CSV_ERROR_MESSAGE) .Fail(); return(NotFound(Result)); } } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.NO_FILE_ERROR_MESSAGE) .Fail(); 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 async Task<InventoryWeavingDocument> GetExistingModel( InventoryWeavingDocument data) //{ // List<InventoryWeavingDocumentItem> DocsItems = new List<InventoryWeavingDocumentItem>(); // foreach (var i in Id) // { // i.ListItems = i.ListItems.Where(s => s.IsSave).ToList(); // data = data.Items.Where(s => s.Id == ); // 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 = data.Id, // StorageCode = data.StorageCode, // StorageName = data.StorageName, // Remark = "", // Type = data.Type, // Items = DocsItems // }; // return model; //} public async Task <int> UpdateAsync(int id, InventoryWeavingDocument model) { using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { int Updated = 0; int[] Id = model.Items.Select(i => i.Id).ToArray(); var existingModel = this.DbSet.Where(d => d.Id.Equals(id) && d._IsDeleted.Equals(false)).Include(p => p.Items).FirstOrDefault(); //var existingModel = GetExistingModel(Id); //var modelExist = this.DbSet.Where(x => x.Items.Any(s => Id.Contains(s.Id))).ToList(); //var existingModel = this.DbSet.Where(d => d.Id.Equals(id) && d._IsDeleted.Equals(false)).Include(p => p.Items.Any( s=> Id.Contains(s.Id))).FirstOrDefault(); //existingModel = existingModel.Items.Any(s => Id.Contains(s.Id)); //foreach (var existingItem in existingModel.Detail) //{ // GarmentLeftoverWarehouseStock stockIn = GenerateStock(existingItem); // await StockService.StockIn(stockIn, model.ExpenditureNo, model.Id, existingItem.Id); //} foreach (var existingItem in existingModel.Items.Where(x => Id.Contains(x.Id))) { var item = model.Items.FirstOrDefault(i => i.Id == existingItem.Id); if (item != null) { if (existingItem.Quantity != item.Quantity) { existingItem.Quantity = item.Quantity; } if (existingItem.QuantityPiece != item.QuantityPiece) { existingItem.QuantityPiece = item.QuantityPiece; } existingItem.FlagForUpdate(IdentityService.Username, UserAgent); } //else //{ // if (existingItem.Quantity != item.Quantity) // { // existingItem.Quantity = item.Quantity; // } // if (existingItem.QuantityPiece != item.QuantityPiece) // { // existingItem.QuantityPiece = item.QuantityPiece; // } // existingItem.FlagForUpdate(IdentityService.Username, UserAgent); //} } foreach (var item in model.Items.Where(i => i.Id == 0)) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); existingModel.Items.Add(item); } Updated = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { InventoryWeavingMovement movement = GenerateMovement(item); await movementService.UpdateAsync(movement); } transaction.Commit(); return(Updated); } catch (Exception e) { transaction.Rollback(); throw e; } } }
private InventoryWeavingDocumentDetailViewModel MapToViewModelById(InventoryWeavingDocument model) { var vm = new InventoryWeavingDocumentDetailViewModel() { Active = model.Active, Id = model.Id, _CreatedAgent = model._CreatedAgent, _CreatedBy = model._CreatedBy, _CreatedUtc = model._CreatedUtc, _IsDeleted = model._IsDeleted, _LastModifiedAgent = model._LastModifiedAgent, _LastModifiedBy = model._LastModifiedBy, _LastModifiedUtc = model._LastModifiedUtc, BonNo = model.BonNo, Date = model.Date, BonType = model.BonType, StorageId = model.StorageId, StorageCode = model.StorageCode, StorageName = model.StorageName, Type = model.Type, Detail = model.Items.GroupBy(x => x.ReferenceNo).Select(item => new InventoryWeavingItemDetailViewModel() { ReferenceNo = item.Key, Construction = item.First().Construction, ProductOrderNo = item.First().ProductOrderName, Year = item.First().ProductOrderName.Substring(item.First().ProductOrderName.Length - 4, 4), ListItems = item.Select(s => new ItemListDetailViewModel() { Active = s.Active, _CreatedAgent = s._CreatedAgent, _CreatedBy = s._CreatedBy, _CreatedUtc = s._CreatedUtc, Id = s.Id, _IsDeleted = s._IsDeleted, _LastModifiedAgent = s._LastModifiedAgent, _LastModifiedBy = s._LastModifiedBy, _LastModifiedUtc = s._LastModifiedUtc, Grade = s.Grade, //Piece = s.Piece, MaterialName = s.MaterialName, WovenType = s.WovenType, Yarn1 = s.Yarn1, Yarn2 = s.Yarn2, YarnType1 = s.YarnType1, YarnType2 = s.YarnType2, YarnOrigin1 = s.YarnOrigin1, YarnOrigin2 = s.YarnOrigin2, YarnOrigin = s.YarnOrigin1 + " / " + s.YarnOrigin2, Width = s.Width, UomUnit = s.UomUnit, Quantity = s.Quantity, QuantityPiece = s.QuantityPiece, ProductRemark = s.ProductRemark, Barcode = s.Barcode, ProductionOrderDate = s.ProductionOrderDate, //DateTime.ParseExact(s.ProductionOrderDate.Date.ToShortDateString(), "yyyy/MM/dd hh:mm:ss", CultureInfo.CreateSpecificCulture("en-US")), //DateTime.ParseExact(Convert.ToString(s.ProductionOrderDate.Date), "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture), }).ToList() }).ToList() }; return(vm); }
public async Task <InventoryWeavingDocument> MapToModelUpdate(InventoryWeavingDocumentDetailViewModel data) { List <InventoryWeavingDocumentItem> DocsItems = new List <InventoryWeavingDocumentItem>(); foreach (var i in data.Detail) { 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.Quantity, QuantityPiece = d.QuantityPiece, ProductRemark = d.ProductRemark, Barcode = d.Barcode, ProductionOrderDate = d.ProductionOrderDate, //InventoryWeavingDocumentId = d.InventoryWeavingDocumentId }); } } InventoryWeavingDocument model = new InventoryWeavingDocument { BonNo = data.BonNo, BonType = data.BonType, Date = data.Date, StorageId = data.Id, StorageCode = data.StorageCode, StorageName = data.StorageName, Remark = "", Type = data.Type, Items = DocsItems }; return(model); }
private InventoryWeavingDocumentDetailViewModel MapToViewModelById(InventoryWeavingDocument model) { var vm = new InventoryWeavingDocumentDetailViewModel() { Active = model.Active, Id = model.Id, _CreatedAgent = model._CreatedAgent, _CreatedBy = model._CreatedBy, _CreatedUtc = model._CreatedUtc, _IsDeleted = model._IsDeleted, _LastModifiedAgent = model._LastModifiedAgent, _LastModifiedBy = model._LastModifiedBy, _LastModifiedUtc = model._LastModifiedUtc, BonNo = model.BonNo, Date = model.Date, BonType = model.BonType, StorageId = model.StorageId, StorageCode = model.StorageCode, StorageName = model.StorageName, Type = model.Type, Detail = model.Items.GroupBy(x => x.Construction).Select(item => new InventoryWeavingItemDetailViewModel() { Construction = item.First().Construction, ListItems = item.Where(s => s._IsDeleted.Equals(false)).Select(s => new ItemListDetailViewModel() { Active = s.Active, _CreatedAgent = s._CreatedAgent, _CreatedBy = s._CreatedBy, _CreatedUtc = s._CreatedUtc, Id = s.Id, _IsDeleted = s._IsDeleted, _LastModifiedAgent = s._LastModifiedAgent, _LastModifiedBy = s._LastModifiedBy, _LastModifiedUtc = s._LastModifiedUtc, Grade = s.Grade, Piece = s.Piece == "1" ? "BESAR" : s.Piece == "2"? "KECIL": "POTONGAN", MaterialName = s.MaterialName, WovenType = s.WovenType, Yarn1 = s.Yarn1, Yarn2 = s.Yarn2, YarnType1 = s.YarnType1, YarnType2 = s.YarnType2, YarnOrigin1 = s.YarnOrigin1, YarnOrigin2 = s.YarnOrigin2, YarnOrigin = s.YarnOrigin1 + " / " + s.YarnOrigin2, Width = s.Width, UomUnit = s.UomUnit, Quantity = s.Quantity, QuantityPiece = s.QuantityPiece, ProductRemark = s.ProductRemark }).ToList() }).ToList() }; return(vm); }
public void UploadUploadFile_WithoutException_ReturnOK() { string header = "nota,nm_tujuan,benang,type,lusi,pakan,lebar,jlusi,jpakan,alusi,apakan,sp,grade,jenis,piece,meter"; string isi = "nota,nm_tujuan,benang,type,lusi,pakan,lebar,jlusi,jpakan,alusi,apakan,sp,grade,1,1,1"; //---continue var mockFacade = new Mock <IInventoryWeavingDocumentOutService>(); mockFacade.Setup(f => f.UploadData(It.IsAny <InventoryWeavingDocument>(), It.IsAny <string>())).Returns(Task.CompletedTask); mockFacade.Setup(f => f.CsvHeaderUpload).Returns(header.Split(',').ToList()); mockFacade.Setup(f => f.UploadValidate(ref It.Ref <List <InventoryWeavingUploadCsvOutViewModel> > .IsAny, It.IsAny <List <KeyValuePair <string, StringValues> > >())).Returns(new Tuple <bool, List <object> >(true, new List <object>())); mockFacade.Setup(f => f.MapToViewModel(It.IsAny <List <InventoryWeavingUploadCsvOutViewModel> >(), It.IsAny <DateTimeOffset>())).ReturnsAsync(Vm); var MockMapper = new Mock <IMapper>(); var model = new InventoryWeavingDocument() { Date = DateTimeOffset.Now, BonNo = "test01", BonType = "weaving", StorageCode = "test01", StorageId = 2, StorageName = "Test", Type = "OUT", Remark = "Remark", Items = new List <InventoryWeavingDocumentItem>() { new InventoryWeavingDocumentItem() { ProductOrderName = "product", ReferenceNo = "referencce", Construction = "CD", Grade = "A", Piece = "1", MaterialName = "CD", WovenType = "", Yarn1 = "yarn1", Yarn2 = "yarn2", YarnType1 = "yt1", YarnType2 = "yt2", YarnOrigin1 = "yo1", YarnOrigin2 = "yo2", Width = "1", UomUnit = "MTR", UomId = 1, Quantity = 1, QuantityPiece = 1, ProductRemark = "", InventoryWeavingDocumentId = 1, Barcode = "barcode", ProductionOrderDate = DateTime.Now, } } }; MockMapper.Setup(x => x.Map <List <InventoryWeavingDocument> >(It.IsAny <List <InventoryWeavingUploadCsvOutViewModel> >())).Returns(new List <InventoryWeavingDocument>() { model }); var mockIdentityService = new Mock <IIdentityService>(); var mockValidateService = new Mock <IValidateService>(); var mockMapperService = new Mock <IMapper>(); var controller = GetController((mockIdentityService, mockValidateService, mockFacade, mockMapperService)); controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = $"{It.IsAny<int>()}"; controller.ControllerContext.HttpContext.Request.Headers.Add("Content-Type", "multipart/form-data"); var file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(header + "\n" + isi)), 0, Encoding.UTF8.GetBytes(header + "\n" + isi).LongLength, "Data", "test.csv"); controller.ControllerContext.HttpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>(), new FormFileCollection { file }); var response = controller.postCsvFileAsync(DateTime.Now); Assert.NotNull(response.Result); }
private InventoryWeavingDocumentDetailViewModel MapToViewModelById(InventoryWeavingDocument model) { var vm = new InventoryWeavingDocumentDetailViewModel() { Active = model.Active, Id = model.Id, _CreatedAgent = model._CreatedAgent, _CreatedBy = model._CreatedBy, _CreatedUtc = model._CreatedUtc, _IsDeleted = model._IsDeleted, _LastModifiedAgent = model._LastModifiedAgent, _LastModifiedBy = model._LastModifiedBy, _LastModifiedUtc = model._LastModifiedUtc, BonNo = model.BonNo, Date = model.Date, BonType = model.BonType, StorageId = model.StorageId, StorageCode = model.StorageCode, StorageName = model.StorageName, Type = model.Type, Detail = model.Items.GroupBy(x => x.ReferenceNo).Select(item => new InventoryWeavingItemDetailViewModel() { ReferenceNo = item.Key, Construction = item.First().Construction, ProductOrderNo = item.First().ProductOrderName, Year = item.First().ProductOrderName.Substring(item.First().ProductOrderName.Length - 4, 4), ListItems = item.Select(s => new ItemListDetailViewModel() { Active = s.Active, _CreatedAgent = s._CreatedAgent, _CreatedBy = s._CreatedBy, _CreatedUtc = s._CreatedUtc, Id = s.Id, _IsDeleted = s._IsDeleted, _LastModifiedAgent = s._LastModifiedAgent, _LastModifiedBy = s._LastModifiedBy, _LastModifiedUtc = s._LastModifiedUtc, Grade = s.Grade, Piece = s.Piece, MaterialName = s.MaterialName, WovenType = s.WovenType, Yarn1 = s.Yarn1, Yarn2 = s.Yarn2, YarnType1 = s.YarnType1, YarnType2 = s.YarnType2, YarnOrigin1 = s.YarnOrigin1, YarnOrigin2 = s.YarnOrigin2, YarnOrigin = s.YarnOrigin1 + " / " + s.YarnOrigin2, Width = s.Width, UomUnit = s.UomUnit, Quantity = s.Quantity, QuantityPiece = s.QuantityPiece, ProductRemark = s.ProductRemark }).ToList() }).ToList() }; return(vm); }
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 = data.bonType == "ADJ MASUK" ? "ADJ_IN":"ADJ_OUT", Items = DocsItems }; return(model); }