public async Task <JsonResult> Add([FromBody] Stantion input) { await CheckPermission(); if (string.IsNullOrEmpty(input.Description) || string.IsNullOrEmpty(input.Name) || string.IsNullOrEmpty(input.StantionType.ToString())) { throw new Exception("Some input parameters NULL"); } var sqlr = new StantionsRepository(_logger); try { if (input.Id != 0) { await sqlr.Update(input); } else { await sqlr.Add(input); } return(Json(new { message = "addOrUpdate OK" })); } catch (Exception e) { throw new Exception($"Can't add or update {this.GetType().ToString()} ex = {e}"); } }
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 }); } }