public async Task <bool> AddUpdateFeeAsync(credit_fee model) { try { if (model.FeeId > 0) { var itemToUpdate = await _dataContext.credit_fee.FindAsync(model.FeeId); _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model); } else { await _dataContext.credit_fee.AddAsync(model); } return(await _dataContext.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <FeeRegRespObj> > GetFeeByIdAsync([FromBody] AddUpdateFeeObj model) { try { credit_fee item = null; if (model.FeeId > 0) { item = await _repo.GetFeeByIdAsync(model.FeeId); if (item == null) { return new FeeRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Item does not Exist" } } } } ; } var domainObj = new credit_fee(); domainObj.FeeId = model.FeeId > 0 ? model.FeeId : 0; domainObj.FeeName = model.FeeName; domainObj.IsIntegral = model.IsIntegral; domainObj.TotalFeeGL = model.TotalFeeGL; domainObj.Active = true; domainObj.CreatedBy = string.Empty; domainObj.CreatedOn = DateTime.Today; domainObj.Deleted = false; domainObj.UpdatedBy = string.Empty; domainObj.UpdatedOn = model.FeeId > 0 ? DateTime.Today : DateTime.Today; var isDone = await _repo.AddUpdateFeeAsync(domainObj); return(new FeeRegRespObj { FeeId = domainObj.FeeId, Status = new APIResponseStatus { IsSuccessful = isDone ? true : false, Message = new APIResponseMessage { FriendlyMessage = isDone ? "successful" : "Unsuccessful" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new FeeRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }
public async Task <bool> UploadFeeAsync(List <byte[]> record, string createdBy) { try { if (record == null) { return(false); } ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List <credit_fee> uploadedRecord = new List <credit_fee>(); if (record.Count() > 0) { foreach (var byteItem in record) { using (MemoryStream stream = new MemoryStream(byteItem)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[0]; int totalRows = workSheet.Dimension.Rows; for (int i = 2; i <= totalRows; i++) { var item = new credit_fee { FeeName = workSheet.Cells[i, 1].Value.ToString(), IsIntegral = bool.Parse(workSheet.Cells[i, 2].Value.ToString()), }; uploadedRecord.Add(item); } } } } if (uploadedRecord.Count > 0) { foreach (var item in uploadedRecord) { var category = _dataContext.credit_fee.Where(x => x.FeeName == item.FeeName && x.Deleted == false).FirstOrDefault(); if (category != null) { category.FeeName = item.FeeName; category.IsIntegral = (bool)item.IsIntegral; category.Active = true; category.Deleted = false; category.UpdatedBy = createdBy; category.UpdatedOn = DateTime.Now; } else { var structure = new credit_fee { FeeName = item.FeeName, IsIntegral = (bool)item.IsIntegral, Active = true, Deleted = false, CreatedBy = createdBy, CreatedOn = DateTime.Now, }; //structures.Add(structure); await _dataContext.credit_fee.AddAsync(structure); } } } var response = _dataContext.SaveChanges() > 0; return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }