public async Task <IActionResult> Post([FromBody] TransferInDocViewModel ViewModel) { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService)); validateService.Validate(ViewModel); var model = mapper.Map <TransferInDoc>(ViewModel); await facade.Create(model, identityService.Username); // await facade.Crea 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 <int> Void(int id, string user, int clientTimeZoneOffset = 7) { int Updated = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { var oldM = DbSet.Where(m => m.Id == id) .Include(m => m.Details) .FirstOrDefault(); if (oldM != null && oldM.Id == id) { oldM.isVoid = true; oldM.FlagForUpdate(IdentityService.Username, UserAgent); TransferInDocViewModel transferInDocView = new TransferInDocViewModel(); List <TransferInDocItemViewModel> transferInDocItems = new List <TransferInDocItemViewModel>(); foreach (var i in oldM.Details) { transferInDocItems.Add(new TransferInDocItemViewModel { item = new ItemViewModels { articleRealizationOrder = i.ItemArticleRealizationOrder, code = i.ItemCode, domesticCOGS = i.ItemDomesticCOGS, domesticRetail = i.ItemDomesticRetail, domesticSale = i.ItemDomesticSale, domesticWholesale = i.ItemDomesticWholeSale, name = i.ItemName, size = i.ItemSize, uom = i.ItemUom, _id = i.ItemId }, remark = oldM.Remark, sendquantity = i.Quantity }); } transferInDocView.code = GenerateCode("voidsales"); transferInDocView.destination = new DestinationViewModel { code = oldM.StoreStorageCode, name = oldM.StoreStorageName, _id = oldM.StoreStorageId }; transferInDocView.reference = oldM.Code; transferInDocView.source = new SourceViewModel { code = oldM.StoreStorageCode, name = oldM.StoreStorageName, _id = oldM.StoreStorageId }; transferInDocView.items = transferInDocItems; string warehouseUri = "transfer-in/for-pos"; var httpClient = (IHttpClientService)ServiceProvider.GetService(typeof(IHttpClientService)); var response = await httpClient.PostAsync($"{APIEndpoint.Warehouse}{warehouseUri}", new StringContent(JsonConvert.SerializeObject(transferInDocView).ToString(), Encoding.UTF8, General.JsonMediaType)); response.EnsureSuccessStatusCode(); //if(oldM.isReturn == true) //{ //} } Updated = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }
public async Task <SalesDoc> Create(SalesDoc model) { int Created = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { string code = GenerateCode("sales"); model.Code = code; model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); if (model.isReturn != true) { model.isReturn = false; } model.isVoid = false; TransferOutDocViewModel transferOutDocViewModel = new TransferOutDocViewModel(); List <TransferOutDocItemViewModel> transferOutDocItemViewModels = new List <TransferOutDocItemViewModel>(); TransferInDocViewModel transferInDocView = new TransferInDocViewModel(); List <TransferInDocItemViewModel> transferInDocItemViews = new List <TransferInDocItemViewModel>(); transferOutDocViewModel.code = code; transferOutDocViewModel.reference = code; transferOutDocViewModel.source = new SourceViewModel { _id = model.StoreStorageId, code = model.StoreStorageCode, name = model.StoreStorageName }; transferOutDocViewModel.destination = new DestinationViewModel { _id = model.StoreStorageId, code = model.StoreStorageCode, name = model.StoreStorageName }; transferOutDocViewModel.remark = model.Remark; bool isAnyTransferIn = false; transferInDocView.code = code; transferInDocView.reference = code; transferInDocView.source = new SourceViewModel { _id = model.StoreStorageId, code = model.StoreStorageCode, name = model.StoreStorageName }; transferInDocView.destination = new DestinationViewModel { _id = model.StoreStorageId, code = model.StoreStorageCode, name = model.StoreStorageName }; transferInDocView.remark = model.Remark; foreach (var item in model.Details) { if (!item.isReturn) { transferOutDocItemViewModels.Add(new TransferOutDocItemViewModel { articleRealizationOrder = item.ItemArticleRealizationOrder, remark = model.Remark, quantity = item.Quantity, item = new ItemViewModels { articleRealizationOrder = item.ItemArticleRealizationOrder, code = item.ItemCode, domesticCOGS = item.ItemDomesticCOGS, domesticRetail = item.ItemDomesticRetail, domesticSale = item.ItemDomesticSale, domesticWholesale = item.ItemDomesticWholeSale, name = item.ItemName, size = item.ItemSize, uom = item.ItemUom, _id = item.ItemId, } }); } else if (item.isReturn) { transferInDocItemViews.Add(new TransferInDocItemViewModel { remark = model.Remark, sendquantity = item.Quantity, item = new ItemViewModels { articleRealizationOrder = item.ItemArticleRealizationOrder, code = item.ItemCode, domesticCOGS = item.ItemDomesticCOGS, domesticRetail = item.ItemDomesticRetail, domesticSale = item.ItemDomesticSale, domesticWholesale = item.ItemDomesticWholeSale, name = item.ItemName, size = item.ItemSize, uom = item.ItemUom, _id = item.ItemId, } }); isAnyTransferIn = true; } item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } transferOutDocViewModel.items = transferOutDocItemViewModels; transferInDocView.items = transferInDocItemViews; if (isAnyTransferIn) { string warehouseUritransferin = "transfer-in/for-pos"; var httpClienttarnsfer = (IHttpClientService)ServiceProvider.GetService(typeof(IHttpClientService)); var responsetransfer = await httpClienttarnsfer.PostAsync($"{APIEndpoint.Warehouse}{warehouseUritransferin}", new StringContent(JsonConvert.SerializeObject(transferInDocView).ToString(), Encoding.UTF8, General.JsonMediaType)); responsetransfer.EnsureSuccessStatusCode(); } string warehouseUri = "transfer-out/pos"; var httpClient = (IHttpClientService)ServiceProvider.GetService(typeof(IHttpClientService)); var response = await httpClient.PostAsync($"{APIEndpoint.Warehouse}{warehouseUri}", new StringContent(JsonConvert.SerializeObject(transferOutDocViewModel).ToString(), Encoding.UTF8, General.JsonMediaType)); response.EnsureSuccessStatusCode(); model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); Created = model.Id; transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(model); }