[HttpDelete()] //Update public IActionResult Delete([FromBody] Model.Company value) { try { if (!_authorization.Check(Request.Headers["Authorization"])) { return(StatusCode(StatusCodes.Status401Unauthorized)); } int Id = value.Id; if (Id != 0) { int Company = _companyRepo.Update(Id, null, true); if (Company < 1) { return(StatusCode(StatusCodes.Status206PartialContent)); } else if (Company == 1) { return(StatusCode(StatusCodes.Status200OK, Company)); } else { return(StatusCode(StatusCodes.Status501NotImplemented)); } } else { return(StatusCode(StatusCodes.Status405MethodNotAllowed)); } } catch (Helper.RepoException ex) { switch (ex.Type) { case EnumResultTypes.INVALIDARGUMENT: return(StatusCode(StatusCodes.Status400BadRequest)); case EnumResultTypes.NOTFOUND: return(StatusCode(StatusCodes.Status204NoContent)); case EnumResultTypes.SQLERROR: return(StatusCode(StatusCodes.Status408RequestTimeout)); case EnumResultTypes.ERROR: return(StatusCode(StatusCodes.Status500InternalServerError)); default: return(StatusCode(StatusCodes.Status501NotImplemented)); } } catch (NullReferenceException) { return(StatusCode(StatusCodes.Status400BadRequest)); } catch (Exception ex) { ErrHandler.Go(ex, null, null); return(StatusCode(StatusCodes.Status501NotImplemented)); } }
[HttpPost()] //Create public IActionResult Add([FromBody] Company value) { try { if (!_authorization.Check(Request.Headers["Authorization"])) { return(StatusCode(StatusCodes.Status401Unauthorized)); } string name = value.Name; if (name.Length < 1) { return(StatusCode(StatusCodes.Status204NoContent)); } int Company = _companyRepo.Add(name); if (Company < 1) { return(StatusCode(StatusCodes.Status206PartialContent)); } else if (Company == 1) { return(StatusCode(StatusCodes.Status201Created, Company)); } else { return(StatusCode(StatusCodes.Status417ExpectationFailed)); } } catch (Helper.RepoException ex) { switch (ex.Type) { case EnumResultTypes.INVALIDARGUMENT: return(StatusCode(StatusCodes.Status400BadRequest)); case EnumResultTypes.NOTFOUND: return(StatusCode(StatusCodes.Status204NoContent)); case EnumResultTypes.SQLERROR: return(StatusCode(StatusCodes.Status408RequestTimeout)); case EnumResultTypes.ERROR: return(StatusCode(StatusCodes.Status500InternalServerError)); default: return(StatusCode(StatusCodes.Status501NotImplemented)); } } catch (NullReferenceException) { return(StatusCode(StatusCodes.Status400BadRequest)); } catch (Exception ex) { ErrHandler.Go(ex, null, null); return(StatusCode(StatusCodes.Status501NotImplemented)); } }
[HttpGet("{id}")] //Read public IActionResult GetCompany(int Id) { try { if (!_authorization.Check(Request.Headers["Authorization"])) { return(StatusCode(StatusCodes.Status401Unauthorized)); } var Company = _companyRepo.Read(Id); if (Company.Count == 1) { return(StatusCode(StatusCodes.Status302Found, Company)); } else if (Company.Count < 1) { return(StatusCode(StatusCodes.Status204NoContent)); } else if (Company.Count > 1) { return(StatusCode(StatusCodes.Status207MultiStatus)); } else { return(StatusCode(StatusCodes.Status400BadRequest)); } } catch (Helper.RepoException ex) { switch (ex.Type) { case EnumResultTypes.INVALIDARGUMENT: return(StatusCode(StatusCodes.Status400BadRequest)); case EnumResultTypes.NOTFOUND: return(StatusCode(StatusCodes.Status204NoContent)); case EnumResultTypes.SQLERROR: return(StatusCode(StatusCodes.Status408RequestTimeout)); case EnumResultTypes.ERROR: return(StatusCode(StatusCodes.Status500InternalServerError)); default: return(StatusCode(StatusCodes.Status501NotImplemented)); } } catch (NullReferenceException) { return(StatusCode(StatusCodes.Status400BadRequest)); } catch (Exception ex) { ErrHandler.Go(ex, null, null); return(StatusCode(StatusCodes.Status501NotImplemented)); } }