public async Task <IActionResult> Delete(string id) { Guid guid = Guid.Parse(id); VerifyUser(); var usedData = false; var garmentSewingDO = _garmentSewingDORepository.Query.Where(o => o.CuttingOutId == guid).Select(o => new GarmentSewingDO(o)).Single(); _garmentSewingDOItemRepository.Find(x => x.SewingDOId == garmentSewingDO.Identity).ForEach(async sewingDOItem => { if (sewingDOItem.RemainingQuantity < sewingDOItem.Quantity) { usedData = true; } }); if (usedData == true) { return(BadRequest(new { code = HttpStatusCode.BadRequest, error = "Data Sudah Digunakan di Sewing In" })); } else { RemoveGarmentCuttingOutCommand command = new RemoveGarmentCuttingOutCommand(guid); var order = await Mediator.Send(command); return(Ok(order.Identity)); } }
public async Task <IActionResult> Get(string id) { Guid guid = Guid.Parse(id); VerifyUser(); GarmentSewingDODto garmentSewingDO = _garmentSewingDORepository.Find(o => o.Identity == guid).Select(sewingDO => new GarmentSewingDODto(sewingDO) { Items = _garmentSewingDOItemRepository.Find(o => o.SewingDOId == sewingDO.Identity).OrderBy(a => a.Color).ThenBy(i => i.SizeName).Select(sewingDOItem => new GarmentSewingDOItemDto(sewingDOItem)).ToList() } ).FirstOrDefault(); await Task.Yield(); return(Ok(garmentSewingDO)); }
public async Task <GarmentCuttingOut> Handle(RemoveGarmentCuttingOutCommand request, CancellationToken cancellationToken) { var cutOut = _garmentCuttingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentCuttingOut(o)).Single(); var sewingDO = _garmentSewingDORepository.Query.Where(o => o.CuttingOutId == request.Identity).Select(o => new GarmentSewingDO(o)).Single(); Dictionary <Guid, double> cuttingInDetailToBeUpdated = new Dictionary <Guid, double>(); _garmentCuttingOutItemRepository.Find(o => o.CutOutId == cutOut.Identity).ForEach(async cutOutItem => { _garmentCuttingOutDetailRepository.Find(o => o.CutOutItemId == cutOutItem.Identity).ForEach(async cutOutDetail => { if (cuttingInDetailToBeUpdated.ContainsKey(cutOutItem.CuttingInDetailId)) { cuttingInDetailToBeUpdated[cutOutItem.CuttingInDetailId] += cutOutDetail.CuttingOutQuantity; } else { cuttingInDetailToBeUpdated.Add(cutOutItem.CuttingInDetailId, cutOutDetail.CuttingOutQuantity); } cutOutDetail.Remove(); await _garmentCuttingOutDetailRepository.Update(cutOutDetail); }); cutOutItem.Remove(); await _garmentCuttingOutItemRepository.Update(cutOutItem); }); foreach (var cuttingInItem in cuttingInDetailToBeUpdated) { var garmentCuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(x => x.Identity == cuttingInItem.Key).Select(s => new GarmentCuttingInDetail(s)).Single(); garmentCuttingInDetail.SetRemainingQuantity(garmentCuttingInDetail.RemainingQuantity + cuttingInItem.Value); garmentCuttingInDetail.Modify(); await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail); } _garmentSewingDOItemRepository.Find(o => o.SewingDOId == sewingDO.Identity).ForEach(async sewingDOItem => { sewingDOItem.Remove(); await _garmentSewingDOItemRepository.Update(sewingDOItem); }); sewingDO.Remove(); await _garmentSewingDORepository.Update(sewingDO); cutOut.Remove(); await _garmentCuttingOutRepository.Update(cutOut); _storage.Save(); return(cutOut); }