public InventoryWeavingDocumentDetailViewModel ReadById(int id) { var data = this.DbSet.Where(d => d.Id.Equals(id) && d._IsDeleted.Equals(false)) .Include(p => p.Items).FirstOrDefault(); if (data == null) { return(null); } InventoryWeavingDocumentDetailViewModel DocsItems = MapToViewModelById(data); return(DocsItems); }
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)); } }
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); }
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); }