public async Task <bool> AddUpdateBusinessCategoryAsync(deposit_businesscategory model) { try { if (model.BusinessCategoryId > 0) { var itemToUpdate = await _dataContext.deposit_businesscategory.FindAsync(model.BusinessCategoryId); _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model); } else { await _dataContext.deposit_businesscategory.AddAsync(model); } return(await _dataContext.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <BusinessCategoryRegRespObj> > AddUpDateBusinessCategory([FromBody] AddUpdateBusinessCategoryObj model) { try { var user = await _identityServer.UserDataAsync(); deposit_businesscategory item = null; if (model.BusinessCategoryId > 0) { item = await _repo.GetBusinessCategoryByIdAsync(model.BusinessCategoryId); if (item == null) { return new BusinessCategoryRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Item does not Exist" } } } } ; } var domainObj = new deposit_businesscategory(); domainObj.BusinessCategoryId = model.BusinessCategoryId > 0 ? model.BusinessCategoryId : 0; domainObj.Name = model.Name; domainObj.Description = model.Description; domainObj.Active = true; domainObj.CreatedOn = DateTime.Today; domainObj.CreatedBy = user.UserName; domainObj.Deleted = false; domainObj.UpdatedOn = model.BusinessCategoryId > 0 ? DateTime.Today : DateTime.Today; domainObj.UpdatedBy = user.UserName; var isDone = await _repo.AddUpdateBusinessCategoryAsync(domainObj); return(new BusinessCategoryRegRespObj { BusinessCategoryId = domainObj.BusinessCategoryId, Status = new APIResponseStatus { IsSuccessful = isDone ? true : false, Message = new APIResponseMessage { FriendlyMessage = isDone ? "successful" : "Unsuccessful" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); return(new BusinessCategoryRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }
public async Task <bool> UploadBusinessCategoryAsync(List <byte[]> record, string createdBy) { try { if (record == null) { return(false); } ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List <deposit_businesscategory> uploadedRecord = new List <deposit_businesscategory>(); 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 deposit_businesscategory { Name = workSheet.Cells[i, 1].Value.ToString(), Description = workSheet.Cells[i, 2].Value.ToString(), }; uploadedRecord.Add(item); } } } } if (uploadedRecord.Count > 0) { foreach (var item in uploadedRecord) { var category = _dataContext.deposit_businesscategory.Where(x => x.BusinessCategoryId == item.BusinessCategoryId && x.Deleted == false).FirstOrDefault(); if (category != null) { category.Name = item.Name; category.Description = item.Description; category.Active = true; category.Deleted = false; category.UpdatedBy = createdBy; category.UpdatedOn = DateTime.Now; } else { var businesscategory = new deposit_businesscategory { Name = item.Name, Description = item.Description, Active = true, Deleted = false, CreatedBy = createdBy, CreatedOn = DateTime.Now, }; await _dataContext.deposit_businesscategory.AddAsync(businesscategory); } } } var response = _dataContext.SaveChanges() > 0; return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }