public IActionResult Get([FromQuery] SubSupplier parameters = null) { try { var model = repository.Get(parameters); return(Ok(model)); } catch (Exception ex) { logger.LogError(ex.GetExceptionMessages()); return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.FetchError)); } }
public PurchaseTransaction WeighoutPurchase(Inyard model) { var refNum = dbContext.ReferenceNumbers.FirstOrDefault(); updateRelatedTableColumns(ref model); var weekDetail = new WeekDetail(model.DateTimeOut.Value); var correctedMC = mcRepo.GetCorrectedMC(model.MC, model.NetWt); var newPurchase = new PurchaseTransaction() { BaleCount = model.BaleCount, BaleTypeDesc = baleTypeRepository.Get().Where(a => a.BaleTypeId == model.BaleTypeId).Take(1).Select(a => a.BaleTypeDesc).FirstOrDefault(), BaleTypeId = model.BaleTypeId, BalingStationNum = model.BalingStationNum, BalingStationCode = model.BalingStationCode, BalingStationName = model.BalingStationName, CategoryDesc = model.CategoryDesc, CategoryId = model.CategoryId, Corrected10 = correctedMC.Corrected10, Corrected12 = correctedMC.Corrected12, Corrected14 = correctedMC.Corrected14, Corrected15 = correctedMC.Corrected15, DateTimeIn = model.DateTimeIn, DateTimeOut = model.IsOfflineOut ?? false ? model.DateTimeIn : DateTime.Now, DriverName = model.DriverName?.ToUpper(), DRNum = model.DRNum?.ToUpper(), FirstDay = weekDetail.FirstDay, FactoryWt = model.PlantNetWt, GrossWt = model.GrossWt, IsOfflineIn = model.IsOfflineIn, IsOfflineOut = model.IsOfflineOut ?? false, LastDay = weekDetail.LastDay, MC = model.MC, MCDate = model.MoistureReaderLogs.FirstOrDefault()?.DTLog, MCStatus = model.MCStatus, MoistureReaderProcess = model.MoistureReaderProcess, MoistureReaderDesc = model.MoistureReaderDesc, MoistureReaderId = model.MoistureReaderId, MoistureReaderLogs = model.MoistureReaderLogs, MoistureSettingsId = 1, OT = model.OT, NetWt = model.NetWt, PM = model.PM, PurchaseOrderId = model.PurchaseOrderId, PONum = model.PONum, POType = model.POType, Price = model.Price, PrintCount = 0, RawMaterialDesc = model.CommodityDesc, RawMaterialId = model.CommodityId, ReceiptNum = refNum.PurchaseReceiptNum, Remarks = model.Remarks?.ToUpper(), SignatoryId = 1, SourceCategoryDesc = model.SourceCategoryDesc, SourceCategoryId = model.SourceCategoryId, SourceId = model.SourceId, SourceName = model.SourceName, SupplierId = model.ClientId, SupplierName = model.ClientName, SubSupplierName = model.SubSupplierName?.ToUpper(), TareWt = model.TareWt, TimeZoneIn = model.DateTimeIn.GetTimeZone(), TimeZoneOut = model.DateTimeOut.GetTimeZone(), Trip = model.Trip?.ToUpper(), VehicleNum = model.VehicleNum?.ToUpper(), VehicleTypeCode = model.VehicleTypeCode, VehicleTypeId = model.VehicleTypeId, WeekDay = weekDetail.WeekDay, WeekNum = weekDetail.WeekNum, WeigherInId = model.WeigherInId, WeigherInName = model.WeigherInName, WeigherOutId = model.WeigherOutId, WeigherOutName = model.WeigherOutName }; dbContext.PurchaseTransactions.Add(newPurchase); if (subSupplierRepository.Get().Count(a => a.SubSupplierName == model.SubSupplierName) == 0) { dbContext.SubSuppliers.Add(new SubSupplier() { SubSupplierName = model.SubSupplierName?.Trim(), IsActive = true }); } refNum.PurchaseReceiptNum = String.Format(StringFormats.REFNO_FORMAT, Convert.ToInt32(refNum.PurchaseReceiptNum) + 1); dbContext.ReferenceNumbers.Update(refNum); dbContext.Inyards.Remove(model); dbContext.SaveChanges(); if (model.IsOfflineOut ?? false) { var auditLog = new AuditLog() { AuditLogEventId = auditLogEventRepository.GetOfflineOutEventId(), UserAccountId = model.WeigherInId, Notes = formatPurchaseOfflineOutEvent(newPurchase) }; auditLogRepository.Create(auditLog); } balingStationRepository.CheckAndCreateStockStatusReminder(); return(newPurchase); }