public async Task <IResponseDTO> CreateVat(CreateUpdateVatDto options, int userId) { try { var vat = new Data.DbModels.LookupSchema.VAT { VatPercentage = options.VatPercentage }; await _appDbContext.VATs.AddAsync(vat); // save to the database var save = await _appDbContext.SaveChangesAsync(); if (save == 0) { _response.IsPassed = false; _response.Message = "Database did not save the object"; return(_response); } _response.IsPassed = true; _response.Message = "VAT is created successfully"; } catch (Exception ex) { _response.Data = null; _response.IsPassed = false; _response.Message = "Error " + ex.Message; } return(_response); }
public async Task <IResponseDTO> UpdateVat(int id, CreateUpdateVatDto options, int userId) { try { var vat = _appDbContext.VATs.FirstOrDefault(x => x.Id == id); if (vat == null) { _response.IsPassed = false; _response.Message = "Invalid id"; return(_response); } vat.VatPercentage = options.VatPercentage; _appDbContext.VATs.Update(vat); // save to the database var save = await _appDbContext.SaveChangesAsync(); if (save == 0) { _response.IsPassed = false; _response.Message = "Database did not save the object"; return(_response); } _response.IsPassed = true; _response.Message = "VAT is updated successfully"; } catch (Exception ex) { _response.Data = null; _response.IsPassed = false; _response.Message = "Error " + ex.Message; } return(_response); }
public async Task <IResponseDTO> UpdateVat([FromRoute] int id, [FromBody] CreateUpdateVatDto options) { _response = await _vatService.UpdateVat(id, options, LoggedInUserId); return(_response); }