public async Task <JsonResult> Delete([FromBody] Stantion stantion) { await CheckPermission(); var cer = new StantionsRepository(_logger); await cer.Delete(stantion.Id); return(Json(new { message = "Delete OK" })); }
public async Task <DictionaryCrudResponse> StantionCrud(DictionaryCrudRequest input) { var data = input.Stantion; if (data == null && input.IdToDelete == null) { throw new ValidationException("Не распарсилось"); } var sqlR = new StantionsRepository(_logger); if (input?.IdToDelete != null) { await sqlR.Delete((int)input.IdToDelete); return(new DictionaryCrudResponse { IsDeleted = true, Stantion = data }); } var all = await sqlR.GetAll(); if (all.Any(x => x.Name.Equals(input.Stantion.Name))) { throw new ValidationException(Error.AlreadyAddWithThisName); } if (data?.Id == 0) { var item = await sqlR.Add(data); return(new DictionaryCrudResponse { IsAdd = true, Stantion = item }); } else { var item = await sqlR.Update(data); return(new DictionaryCrudResponse { IsUpdated = true, Stantion = item }); } }