public async Task <IActionResult> Edit([FromBody] SgstMasterModel editSgstMaster) { ServiceResponseModel <SgstMasterModel> response = new ServiceResponseModel <SgstMasterModel>(); try { if (editSgstMaster.SgstId < 0) { throw new ArgumentNullException("SgstId is required"); } if (string.IsNullOrWhiteSpace(editSgstMaster.SgstDetail)) { throw new ArgumentNullException("SgstDetail is required"); } if (editSgstMaster.SgstId < 0) { throw new ArgumentNullException("SgstId is required"); } response = await _sgstService.Edit(editSgstMaster); if (response.Data == null) { return(NotFound(response)); } } catch (Exception ex) { _logger.LogError(ex.StackTrace); response.Success = false; response.Message = ex.Message; } return(Ok(response)); }
public async Task <ServiceResponseModel <SgstMasterModel> > GetSgstByCode(int sgstId) { SgstMaster dbSgstMaster = await UnitOfWork.SgstMasters.GetSgstByCode(sgstId); SgstMasterModel sgstMasterModel = _mapper.Map <SgstMasterModel>(dbSgstMaster); ServiceResponseModel <SgstMasterModel> serviceResponse = new ServiceResponseModel <SgstMasterModel> { Data = sgstMasterModel }; return(serviceResponse); }
public async Task <ServiceResponseModel <SgstMasterModel> > Add(SgstMasterModel newSgstMaster) { ServiceResponseModel <SgstMasterModel> serviceResponse = new ServiceResponseModel <SgstMasterModel>(); SgstMaster sgstMaster = _mapper.Map <SgstMaster>(newSgstMaster); await UnitOfWork.SgstMasters.AddAsync(sgstMaster); await UnitOfWork.Complete(); serviceResponse.Data = newSgstMaster; return(serviceResponse); }
public async Task <ServiceResponseModel <SgstMasterModel> > Edit(SgstMasterModel editSgstMasterModel) { ServiceResponseModel <SgstMasterModel> serviceResponse = new ServiceResponseModel <SgstMasterModel>(); SgstMaster editSgstMaster = await UnitOfWork.SgstMasters.SingleOrDefaultAsync(s => s.SgstId == editSgstMasterModel.SgstId); _mapper.Map <SgstMasterModel, SgstMaster>(editSgstMasterModel, editSgstMaster); serviceResponse.Data = editSgstMasterModel; UnitOfWork.SgstMasters.Update(editSgstMaster); await UnitOfWork.Complete(); return(serviceResponse); }
public async Task <ServiceResponseModel <SgstMasterModel> > Delete(int sgstId) { ServiceResponseModel <SgstMasterModel> serviceResponse = new ServiceResponseModel <SgstMasterModel>(); SgstMaster delSgstMaster = await UnitOfWork.SgstMasters.SingleOrDefaultAsync(s => s.SgstId == sgstId); UnitOfWork.SgstMasters.Remove(delSgstMaster); await UnitOfWork.Complete(); SgstMasterModel delSgstMasterModel = _mapper.Map <SgstMasterModel>(delSgstMaster); serviceResponse.Data = delSgstMasterModel; return(serviceResponse); }
public async Task <IActionResult> GetAll([FromQuery] PageParams pageParams, [FromBody] SgstMasterModel getSgstMaster) { ServiceResponseModel <IEnumerable <SgstMaster> > response = new ServiceResponseModel <IEnumerable <SgstMaster> >(); try { var sgstList = await _sgstService.GetAll(pageParams, getSgstMaster); Response.AddPaginationHeader(sgstList.CurrentPage, sgstList.PageSize, sgstList.TotalCount, sgstList.TotalPages); response.Data = sgstList; } catch (Exception ex) { _logger.LogError(ex.StackTrace); response.Success = false; response.Message = ex.Message; } return(Ok(response)); }
public async Task <PagedList <SgstMaster> > GetAll(PageParams pageParams, SgstMasterModel getSgstMaster) { var query = _context.SgstMasters.AsQueryable(); switch (getSgstMaster.OrderBy) { case "sgstDetail": query = query.OrderBy(c => c.SgstDetail); break; case "sgstRate": query = query.OrderBy(c => c.SgstRate); break; default: query = query.OrderBy(c => c.SgstId); break; } return(await PagedList <SgstMaster> .CreateAsync(query, pageParams.PageNumber, pageParams.PageSize)); }