public bool ETOPost(List <int> Ids) { bool IsSuccessful = false; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { var listData = this.DbSet .Where(m => Ids.Contains(m.Id)) .Include(d => d.ExternalTransferOrderItems) .ThenInclude(d => d.ExternalTransferOrderDetails) .ToList(); listData.ForEach(data => { data.IsPosted = true; data._LastModifiedUtc = DateTime.UtcNow; data._LastModifiedAgent = "Service"; data._LastModifiedBy = this.Username; foreach (var item in data.ExternalTransferOrderItems) { item._LastModifiedUtc = DateTime.UtcNow; item._LastModifiedAgent = "Service"; item._LastModifiedBy = this.Username; foreach (var detail in item.ExternalTransferOrderDetails) { detail._LastModifiedUtc = DateTime.UtcNow; detail._LastModifiedAgent = "Service"; detail._LastModifiedBy = this.Username; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah diorder ke Penjualan"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah diorder ke Penjualan"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } } }); this.DbContext.SaveChanges(); IsSuccessful = true; Transaction.Commit(); } catch (DbUpdateConcurrencyException) { Transaction.Rollback(); throw; } } return(IsSuccessful); }
public override async Task <int> CreateModel(InternalTransferOrder Model) { int Created = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { Model = await this.CustomCodeGenerator(Model); Created = await this.CreateAsync(Model); foreach (var detail in Model.InternalTransferOrderDetails) { TransferRequestDetail trd = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); trd.Status = "Sudah diterima Pembelian"; } this.DbContext.SaveChanges(); transaction.Commit(); } catch (ServiceValidationExeption e) { throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults); } catch (Exception e) { transaction.Rollback(); } } return(Created); }
public TransferShippingOrderViewModel MapToViewModel(TransferShippingOrder model) { TransferShippingOrderViewModel viewModel = new TransferShippingOrderViewModel(); PropertyCopier <TransferShippingOrder, TransferShippingOrderViewModel> .Copy(model, viewModel); viewModel.Supplier = new SupplierViewModel() { _id = model.SupplierId, code = model.SupplierCode, name = model.SupplierName }; viewModel.TransferShippingOrderItems = new List <TransferShippingOrderItemViewModel>(); if (model.TransferShippingOrderItems != null) { foreach (TransferShippingOrderItem shippingOrderItem in model.TransferShippingOrderItems) { TransferShippingOrderItemViewModel shippingOrderItemViewModel = new TransferShippingOrderItemViewModel(); PropertyCopier <TransferShippingOrderItem, TransferShippingOrderItemViewModel> .Copy(shippingOrderItem, shippingOrderItemViewModel); shippingOrderItemViewModel.TransferShippingOrderDetails = new List <TransferShippingOrderDetailViewModel>(); if (shippingOrderItem.TransferShippingOrderDetails != null) { foreach (TransferShippingOrderDetail shippingOrderDetail in shippingOrderItem.TransferShippingOrderDetails) { TransferShippingOrderDetailViewModel shippingOrderDetailViewModel = new TransferShippingOrderDetailViewModel(); PropertyCopier <TransferShippingOrderDetail, TransferShippingOrderDetailViewModel> .Copy(shippingOrderDetail, shippingOrderDetailViewModel); TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.SingleOrDefault(d => d.Id == shippingOrderDetailViewModel.TRDetailId); if (transferRequestDetail != null) { int TRId = transferRequestDetail.TransferRequestId; shippingOrderDetailViewModel.TRNo = this.DbContext.TransferRequests.SingleOrDefault(d => d.Id == TRId).TRNo; } shippingOrderDetailViewModel.Product = new ProductViewModel { _id = shippingOrderDetail.ProductId, code = shippingOrderDetail.ProductCode, name = shippingOrderDetail.ProductName }; shippingOrderDetailViewModel.Uom = new UomViewModel { _id = shippingOrderDetail.UomId, unit = shippingOrderDetail.UomUnit }; shippingOrderItemViewModel.TransferShippingOrderDetails.Add(shippingOrderDetailViewModel); } } viewModel.TransferShippingOrderItems.Add(shippingOrderItemViewModel); } } return(viewModel); }
public bool ETOUnpost(int Id) { bool IsSuccessful = false; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { var data = this.DbSet .Include(d => d.ExternalTransferOrderItems) .ThenInclude(d => d.ExternalTransferOrderDetails) .FirstOrDefault(tr => tr.Id == Id && tr._IsDeleted == false); data.IsPosted = false; data._LastModifiedUtc = DateTime.UtcNow; data._LastModifiedAgent = "Service"; data._LastModifiedBy = this.Username; foreach (var item in data.ExternalTransferOrderItems) { item._LastModifiedUtc = DateTime.UtcNow; item._LastModifiedAgent = "Service"; item._LastModifiedBy = this.Username; foreach (var detail in item.ExternalTransferOrderDetails) { detail._LastModifiedUtc = DateTime.UtcNow; detail._LastModifiedAgent = "Service"; detail._LastModifiedBy = this.Username; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah dibuat TO Eksternal"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah dibuat TO Eksternal"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } } this.DbContext.SaveChanges(); IsSuccessful = true; Transaction.Commit(); } catch (DbUpdateConcurrencyException) { Transaction.Rollback(); throw; } } return(IsSuccessful); }
public override async Task <int> CreateModel(ExternalTransferOrder Model) { int Created = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { Model.ETONo = await this.GenerateExternalTransferOrderNo(Model); Created = await this.CreateAsync(Model); foreach (var item in Model.ExternalTransferOrderItems) { foreach (var detail in item.ExternalTransferOrderDetails) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah dibuat TO Eksternal"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah dibuat TO Eksternal"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } InternalTransferOrder internalTransferOrder = this.DbContext.InternalTransferOrders.FirstOrDefault(s => s.Id == item.ITOId); internalTransferOrder.IsPost = true; internalTransferOrder._LastModifiedUtc = DateTime.UtcNow; internalTransferOrder._LastModifiedAgent = "Service"; internalTransferOrder._LastModifiedBy = this.Username; } this.DbContext.SaveChanges(); Transaction.Commit(); } catch (ServiceValidationExeption e) { throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults); } catch (Exception) { Transaction.Rollback(); } } return(Created); }
public override async Task <int> UpdateModel(int Id, TransferRequest Model) { TransferRequestDetailService transferRequestDetailService = this.ServiceProvider.GetService <TransferRequestDetailService>(); transferRequestDetailService.Username = this.Username; int Updated = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { HashSet <int> transferRequestDetails = new HashSet <int>(transferRequestDetailService.DbSet .Where(w => w.TransferRequestId.Equals(Id)) .Select(s => s.Id)); Updated = await this.UpdateAsync(Id, Model); foreach (int transferRequestDetail in transferRequestDetails) { TransferRequestDetail model = Model.TransferRequestDetails.FirstOrDefault(prop => prop.Id.Equals(transferRequestDetail)); if (model == null) { await transferRequestDetailService.DeleteModel(transferRequestDetail); } else { await transferRequestDetailService.UpdateModel(transferRequestDetail, model); } } foreach (TransferRequestDetail transferRequestDetail in Model.TransferRequestDetails) { if (transferRequestDetail.Id.Equals(0)) { await transferRequestDetailService.CreateModel(transferRequestDetail); } } transaction.Commit(); } catch (Exception e) { transaction.Rollback(); } } return(Updated); }
public override async Task <int> CreateModel(TransferShippingOrder Model) { int Created = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { Model.SONo = await this.CustomCodeGenerator(Model); Created = await this.CreateAsync(Model); foreach (var item in Model.TransferShippingOrderItems) { foreach (var detail in item.TransferShippingOrderDetails) { TransferDeliveryOrderDetail transferDeliveryOrderDetail = this.DbContext.TransferDeliveryOrderDetails.FirstOrDefault(s => s.Id == detail.DODetailId); transferDeliveryOrderDetail.ShippingOrderQuantity += (int)detail.DeliveryQuantity; transferDeliveryOrderDetail.RemainingQuantity -= (int)detail.DeliveryQuantity; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } } this.DbContext.SaveChanges(); Transaction.Commit(); } catch (ServiceValidationExeption e) { throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults); } catch (Exception) { Transaction.Rollback(); } } return(Created); }
public TransferRequest MapToModel(TransferRequestViewModel viewModel) { TransferRequest model = new TransferRequest(); PropertyCopier <TransferRequestViewModel, TransferRequest> .Copy(viewModel, model); model.TRDate = viewModel.trDate; model.RequestedArrivalDate = viewModel.requestedArrivalDate; model.UnitId = viewModel.unit._id; model.UnitCode = viewModel.unit.code; model.UnitName = viewModel.unit.name; model.DivisionId = viewModel.unit.divisionId; model.DivisionCode = viewModel.unit.divisionCode; model.DivisionName = viewModel.unit.divisionName; model.CategoryCode = viewModel.category.code; model.CategoryId = viewModel.category._id; model.CategoryName = viewModel.category.name; model.Remark = viewModel.remark; model.TRNo = viewModel.trNo; model.IsPosted = viewModel.isPosted; model.IsCanceled = viewModel.isCanceled; model.TransferRequestDetails = new List <TransferRequestDetail>(); foreach (TransferRequestDetailViewModel transferRequestDetailViewModel in viewModel.details) { TransferRequestDetail transferRequestDetail = new TransferRequestDetail(); PropertyCopier <TransferRequestDetailViewModel, TransferRequestDetail> .Copy(transferRequestDetailViewModel, transferRequestDetail); transferRequestDetail.ProductId = transferRequestDetailViewModel.product._id; transferRequestDetail.ProductCode = transferRequestDetailViewModel.product.code; transferRequestDetail.ProductName = transferRequestDetailViewModel.product.name; transferRequestDetail.Quantity = transferRequestDetailViewModel.quantity; transferRequestDetail.UomId = transferRequestDetailViewModel.uom._id; transferRequestDetail.UomUnit = transferRequestDetailViewModel.uom.unit; transferRequestDetail.ProductRemark = transferRequestDetailViewModel.productRemark; transferRequestDetail.Grade = transferRequestDetailViewModel.grade; transferRequestDetail.Status = transferRequestDetailViewModel.status; model.TransferRequestDetails.Add(transferRequestDetail); } return(model); }
public override async Task <int> DeleteModel(int Id) { InternalTransferOrderDetailService internalTransferOrderDetailService = this.ServiceProvider.GetService <InternalTransferOrderDetailService>(); int Deleted = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { InternalTransferOrder Model = await this.ReadModelById(Id); Deleted = await this.DeleteAsync(Id); HashSet <int> internalTransferOrderDetails = new HashSet <int>(internalTransferOrderDetailService.DbSet .Where(p => p.ITOId.Equals(Id)) .Select(p => p.Id)); internalTransferOrderDetailService.Username = this.Username; foreach (int detail in internalTransferOrderDetails) { await internalTransferOrderDetailService.DeleteModel(detail); } foreach (var detail in Model.InternalTransferOrderDetails) { TransferRequestDetail trd = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); trd.Status = "Belum diterima Pembelian"; } this.DbContext.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } return(Deleted); }
public bool TRPost(List <int> Ids) { bool IsSuccessful = false; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { var transfer = this.DbSet.Where(m => Ids.Contains(m.Id)).Include(d => d.TransferRequestDetails).ToList(); transfer.ForEach(tr => { tr.IsPosted = true; tr._LastModifiedUtc = DateTime.UtcNow; tr._LastModifiedAgent = "Service"; tr._LastModifiedBy = this.Username; foreach (var data in tr.TransferRequestDetails) { TransferRequestDetail trDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == data.Id); trDetail._LastModifiedUtc = DateTime.UtcNow; trDetail._LastModifiedAgent = "Service"; trDetail._LastModifiedBy = this.Username; } }); this.DbContext.SaveChanges(); IsSuccessful = true; Transaction.Commit(); } catch (DbUpdateConcurrencyException) { Transaction.Rollback(); throw; } } return(IsSuccessful); }
public override async Task <int> DeleteModel(int Id) { int Deleted = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { //ExternalTransferOrder externalTransferOrder = await this.ReadModelById(Id); ExternalTransferOrderItemService externalTransferOrderItemService = ServiceProvider.GetService <ExternalTransferOrderItemService>(); externalTransferOrderItemService.Username = this.Username; ExternalTransferOrderDetailService externalTransferOrderDetailService = ServiceProvider.GetService <ExternalTransferOrderDetailService>(); externalTransferOrderDetailService.Username = this.Username; HashSet <int> ExternalTransferOrderItemIds = new HashSet <int>( this.DbContext.ExternalTransferOrderItems .Where(p => p.ETOId.Equals(Id)) .Select(p => p.Id) ); foreach (int itemId in ExternalTransferOrderItemIds) { HashSet <int> ExternalTransferOrderDetailIds = new HashSet <int>( this.DbContext.ExternalTransferOrderDetails .Where(p => p.ETOItemId.Equals(itemId)) .Select(p => p.Id) ); foreach (int detailId in ExternalTransferOrderDetailIds) { await externalTransferOrderDetailService.DeleteModel(detailId); ExternalTransferOrderItem item = this.DbContext.ExternalTransferOrderItems .Include(d => d.ExternalTransferOrderDetails) .FirstOrDefault(p => p.Id.Equals(itemId)); if (item != null) { foreach (var detail in item.ExternalTransferOrderDetails) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah diterima Pembelian"; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "TO Internal belum diorder"; } InternalTransferOrder internalTransferOrder = this.DbContext.InternalTransferOrders.FirstOrDefault(s => s.Id == item.ITOId); internalTransferOrder.IsPost = false; } } await externalTransferOrderItemService.DeleteModel(itemId); } Deleted = await this.DeleteAsync(Id); this.DbContext.SaveChanges(); Transaction.Commit(); } catch (Exception) { Transaction.Rollback(); } } return(Deleted); }
public override async Task <int> UpdateModel(int Id, ExternalTransferOrder Model) { int Updated = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { ExternalTransferOrderItemService externalTransferOrderItemService = ServiceProvider.GetService <ExternalTransferOrderItemService>(); externalTransferOrderItemService.Username = this.Username; ExternalTransferOrderDetailService externalTransferOrderDetailService = ServiceProvider.GetService <ExternalTransferOrderDetailService>(); externalTransferOrderDetailService.Username = this.Username; HashSet <int> ExternalTransferOrderItemIds = new HashSet <int>( this.DbContext.ExternalTransferOrderItems .Where(p => p.ETOId.Equals(Id)) .Select(p => p.Id) ); foreach (int itemId in ExternalTransferOrderItemIds) { HashSet <int> ExternalTransferOrderDetailIds = new HashSet <int>( this.DbContext.ExternalTransferOrderDetails .Where(p => p.ETOItemId.Equals(itemId)) .Select(p => p.Id) ); ExternalTransferOrderItem externalTransferOrderItem = Model.ExternalTransferOrderItems.FirstOrDefault(p => p.Id.Equals(itemId)); // cek item apakah dihapus (sesuai data yang diubah) if (externalTransferOrderItem == null) { ExternalTransferOrderItem item = this.DbContext.ExternalTransferOrderItems .Include(d => d.ExternalTransferOrderDetails) .FirstOrDefault(p => p.Id.Equals(itemId)); if (item != null) { foreach (var detail in item.ExternalTransferOrderDetails) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah diterima Pembelian"; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "TO Internal belum diorder"; } InternalTransferOrder internalTransferOrder = this.DbContext.InternalTransferOrders.FirstOrDefault(s => s.Id == item.ITOId); internalTransferOrder.IsPost = false; } foreach (int detailId in ExternalTransferOrderDetailIds) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(p => p.Id.Equals(detailId)); await externalTransferOrderDetailService.DeleteModel(detailId); } await externalTransferOrderItemService.DeleteModel(itemId); } else { await externalTransferOrderItemService.UpdateModel(itemId, externalTransferOrderItem); foreach (int detailId in ExternalTransferOrderDetailIds) { ExternalTransferOrderDetail externalTransferOrderDetail = externalTransferOrderItem.ExternalTransferOrderDetails.FirstOrDefault(p => p.Id.Equals(detailId)); await externalTransferOrderDetailService.UpdateModel(detailId, externalTransferOrderDetail); } } } Updated = await this.UpdateAsync(Id, Model); foreach (ExternalTransferOrderItem item in Model.ExternalTransferOrderItems) { if (item.Id == 0) { await externalTransferOrderItemService.CreateModel(item); foreach (var detail in item.ExternalTransferOrderDetails) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah dibuat TO Eksternal"; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah dibuat TO Eksternal"; } InternalTransferOrder internalTransferOrder = this.DbContext.InternalTransferOrders.FirstOrDefault(s => s.Id == item.ITOId); internalTransferOrder.IsPost = true; } } this.DbContext.SaveChanges(); Transaction.Commit(); } catch (Exception) { Transaction.Rollback(); } } return(Updated); }
public override async Task <int> DeleteModel(int Id) { int Deleted = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { //ExternalTransferOrder externalTransferOrder = await this.ReadModelById(Id); TransferDeliveryOrderItemService transferDeliveryOrderItemService = ServiceProvider.GetService <TransferDeliveryOrderItemService>(); transferDeliveryOrderItemService.Username = this.Username; TransferDeliveryOrderDetailService transferDeliveryOrderDetailService = ServiceProvider.GetService <TransferDeliveryOrderDetailService>(); transferDeliveryOrderDetailService.Username = this.Username; HashSet <int> TransferDeliveryOrderItemIds = new HashSet <int>( this.DbContext.TransferDeliveryOrderItems .Where(p => p.DOId.Equals(Id)) .Select(p => p.Id) ); foreach (int itemId in TransferDeliveryOrderItemIds) { HashSet <int> TransferDeliveryOrderDetailIds = new HashSet <int>( this.DbContext.TransferDeliveryOrderDetails .Where(p => p.DOItemId.Equals(itemId)) .Select(p => p.Id) ); foreach (int detailId in TransferDeliveryOrderDetailIds) { await transferDeliveryOrderDetailService.DeleteModel(detailId); TransferDeliveryOrderItem item = this.DbContext.TransferDeliveryOrderItems .Include(d => d.transferDeliveryOrderDetail) .FirstOrDefault(p => p.Id.Equals(itemId)); if (item != null) { foreach (var detail in item.transferDeliveryOrderDetail) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ETODetailId); externalTransferOrderDetail.DOQuantity = (externalTransferOrderDetail.DOQuantity) - (detail.DOQuantity); externalTransferOrderDetail.RemainingQuantity = (externalTransferOrderDetail.RemainingQuantity) + (detail.DOQuantity); externalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; externalTransferOrderDetail._LastModifiedAgent = "Service"; externalTransferOrderDetail._LastModifiedBy = this.Username; if (externalTransferOrderDetail.DealQuantity == detail.RemainingQuantity) { TransferRequestDetail transRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transRequestDetail.Status = "Sudah diorder ke Penjualan"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); transRequestDetail.Status = "Sudah diorder ke Penjualan"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; } else if (externalTransferOrderDetail.RemainingQuantity <= 0) { TransferRequestDetail transRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transRequestDetail.Status = "Sudah diorder semua ke Unit Pengirim"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); transRequestDetail.Status = "Sudah diorder semua ke Unit Pengirim"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; } else if (externalTransferOrderDetail.RemainingQuantity > 0) { TransferRequestDetail transRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transRequestDetail.Status = "Sudah diorder sebagian ke Unit Pengirim"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); transRequestDetail.Status = "Sudah diorder sebagian ke Unit Pengirim"; transRequestDetail._LastModifiedUtc = DateTime.UtcNow; transRequestDetail._LastModifiedAgent = "Service"; transRequestDetail._LastModifiedBy = this.Username; } } } } await transferDeliveryOrderItemService.DeleteModel(itemId); } Deleted = await this.DeleteAsync(Id); this.DbContext.SaveChanges(); Transaction.Commit(); } catch (Exception) { Transaction.Rollback(); } } return(Deleted); }
public override async Task <int> CreateModel(TransferDeliveryOrder Model) { int Created = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { Model.DONo = await this.GenerateTransferDeliveryOrderNo(Model); Created = await this.CreateAsync(Model); foreach (var item in Model.TransferDeliveryOrderItem) { foreach (var detail in item.transferDeliveryOrderDetail) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ETODetailId); externalTransferOrderDetail.DOQuantity = (externalTransferOrderDetail.DOQuantity) + (detail.DOQuantity); externalTransferOrderDetail.RemainingQuantity = (externalTransferOrderDetail.RemainingQuantity) - (detail.DOQuantity); externalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; externalTransferOrderDetail._LastModifiedAgent = "Service"; externalTransferOrderDetail._LastModifiedBy = this.Username; if (externalTransferOrderDetail.RemainingQuantity > 0) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah diorder sebagian ke Unit Pengirim"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah diorder sebagian ke Unit Pengirim"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } else if (externalTransferOrderDetail.RemainingQuantity <= 0) { TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail.Status = "Sudah diorder semua ke Unit Pengirim"; transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail.Status = "Sudah diorder semua ke Unit Pengirim"; internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; } } } this.DbContext.SaveChanges(); transaction.Commit(); } catch (ServiceValidationExeption e) { throw new ServiceValidationExeption(e.ValidationContext, e.ValidationResults); } catch (Exception e) { transaction.Rollback(); } } return(Created); }
public override async Task <int> UpdateModel(int Id, TransferShippingOrder Model) { int Updated = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { TransferShippingOrderItemService shippingOrderItemService = ServiceProvider.GetService <TransferShippingOrderItemService>(); shippingOrderItemService.Username = this.Username; TransferShippingOrderDetailService shippingOrderDetailService = ServiceProvider.GetService <TransferShippingOrderDetailService>(); shippingOrderDetailService.Username = this.Username; HashSet <int> ShippingOrderItemIds = new HashSet <int>( this.DbContext.TransferShippingOrderItems .Where(p => p.SOId.Equals(Id)) .Select(p => p.Id) ); foreach (int itemId in ShippingOrderItemIds) { HashSet <int> ShippingOrderDetailIds = new HashSet <int>( this.DbContext.TransferShippingOrderDetails .Where(p => p.SOItemId.Equals(itemId)) .Select(p => p.Id) ); TransferShippingOrderItem shippingOrderItemNew = Model.TransferShippingOrderItems.FirstOrDefault(p => p.Id.Equals(itemId)); if (shippingOrderItemNew == null) { TransferShippingOrderItem item = this.DbContext.TransferShippingOrderItems .Include(d => d.TransferShippingOrderDetails) .FirstOrDefault(p => p.Id.Equals(itemId)); if (item != null) { foreach (var detail in item.TransferShippingOrderDetails) { TransferDeliveryOrderDetail transferDeliveryOrderDetail = this.DbContext.TransferDeliveryOrderDetails.FirstOrDefault(s => s.Id == detail.DODetailId); transferDeliveryOrderDetail.ShippingOrderQuantity -= (int)detail.DeliveryQuantity; transferDeliveryOrderDetail.RemainingQuantity += (int)detail.DeliveryQuantity; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; if (transferDeliveryOrderDetail.RemainingQuantity == transferDeliveryOrderDetail.DOQuantity) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ETODetailId); transferRequestDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; internalTransferOrderDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; } else { transferRequestDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; internalTransferOrderDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; } } } foreach (int detailId in ShippingOrderDetailIds) { await shippingOrderDetailService.DeleteModel(detailId); } await shippingOrderItemService.DeleteModel(itemId); } else { await shippingOrderItemService.UpdateModel(itemId, shippingOrderItemNew); foreach (int detailId in ShippingOrderDetailIds) { TransferShippingOrderDetail shippingOrderDetailNew = shippingOrderItemNew.TransferShippingOrderDetails.FirstOrDefault(p => p.Id.Equals(detailId)); if (shippingOrderDetailNew == null) { await shippingOrderDetailService.DeleteModel(detailId); } else { await shippingOrderDetailService.UpdateModel(detailId, shippingOrderDetailNew); TransferShippingOrderDetail shippingOrderDetailOld = this.DbContext.TransferShippingOrderDetails.FirstOrDefault(p => p.Id.Equals(detailId)); TransferDeliveryOrderDetail transferDeliveryOrderDetail = this.DbContext.TransferDeliveryOrderDetails.FirstOrDefault(s => s.Id == shippingOrderDetailNew.DODetailId); transferDeliveryOrderDetail.ShippingOrderQuantity = transferDeliveryOrderDetail.ShippingOrderQuantity - (int)shippingOrderDetailOld.DeliveryQuantity + (int)shippingOrderDetailNew.DeliveryQuantity; transferDeliveryOrderDetail.RemainingQuantity = transferDeliveryOrderDetail.RemainingQuantity + (int)shippingOrderDetailOld.DeliveryQuantity - (int)shippingOrderDetailNew.DeliveryQuantity; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == shippingOrderDetailNew.TRDetailId); transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == shippingOrderDetailNew.ITODetailId); internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; if (transferDeliveryOrderDetail.RemainingQuantity == transferDeliveryOrderDetail.DOQuantity) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(s => s.Id == shippingOrderDetailNew.ETODetailId); transferRequestDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; internalTransferOrderDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; } else { transferRequestDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; internalTransferOrderDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; } } } } } Updated = await this.UpdateAsync(Id, Model); foreach (TransferShippingOrderItem item in Model.TransferShippingOrderItems) { if (item.Id == 0) { await shippingOrderItemService.CreateModel(item); foreach (var detail in item.TransferShippingOrderDetails) { TransferDeliveryOrderDetail transferDeliveryOrderDetail = this.DbContext.TransferDeliveryOrderDetails.FirstOrDefault(s => s.Id == detail.DODetailId); transferDeliveryOrderDetail.ShippingOrderQuantity += (int)detail.DeliveryQuantity; transferDeliveryOrderDetail.RemainingQuantity -= (int)detail.DeliveryQuantity; TransferRequestDetail transferRequestDetail = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId); transferRequestDetail._LastModifiedUtc = DateTime.UtcNow; transferRequestDetail._LastModifiedAgent = "Service"; transferRequestDetail._LastModifiedBy = this.Username; InternalTransferOrderDetail internalTransferOrderDetail = this.DbContext.InternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ITODetailId); internalTransferOrderDetail._LastModifiedUtc = DateTime.UtcNow; internalTransferOrderDetail._LastModifiedAgent = "Service"; internalTransferOrderDetail._LastModifiedBy = this.Username; if (transferDeliveryOrderDetail.RemainingQuantity == transferDeliveryOrderDetail.DOQuantity) { ExternalTransferOrderDetail externalTransferOrderDetail = this.DbContext.ExternalTransferOrderDetails.FirstOrDefault(s => s.Id == detail.ETODetailId); transferRequestDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; internalTransferOrderDetail.Status = externalTransferOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian ke Unit Pengirim" : "Barang Sudah dikirim semua ke Unit Pengirim"; } else { transferRequestDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; internalTransferOrderDetail.Status = transferDeliveryOrderDetail.RemainingQuantity > 0 ? "Barang Sudah dikirim sebagian" : "Barang Sudah dikirim semua"; } } } } this.DbContext.SaveChanges(); Transaction.Commit(); } catch (Exception) { Transaction.Rollback(); } } return(Updated); }