public FileEditor Post(FileEditor file) { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } try { const string fileName = "Unititled"; return(EditorServices.Create(file?.Name ?? fileName, _user.Id)); } catch (NotFound ex) { throw ExceptionResponse.NotFound(Request, ex.Message); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public void Save(int userId, [FromBody] List <Product> products) { try { if (products.Count == 0) { throw new RequestForbidden("Invalid Request"); } UserProfile _user = AuthManager.CurrentUser; if (_user == null || userId != _user.Id) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } ProductServices.Save(userId, products); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public IEnumerable <ReaderData> Get(string id) { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } try { return(null); } catch (NotFound ex) { throw ExceptionResponse.NotFound(Request, ex.Message); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public IEnumerable <FileEditor> Get() { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } try { IEnumerable <FileEditor> editors = EditorServices.GetAll(_user.Id); return(editors); } catch (NotFound ex) { throw ExceptionResponse.NotFound(Request, ex.Message); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
// POST api/<controller> public void Post(string id, [FromBody] IEnumerable <ReaderData> data) { try { if (data == null) { throw new RequestForbidden(new ErrorResponse(ErrorResponseCode.InvalidRequestError, Messages.RequestForbidden)); } //EditorServices.SegregateOperations(ops.ToList(), Convert.ToInt32(id)); } catch (RequestForbidden r) { throw ExceptionResponse.Forbidden(Request, r.Message); } catch (Exception) { throw; } }
public IEnumerable <UserProduct> Get(int userId) { try { UserProfile _user = AuthManager.CurrentUser; if (_user == null || userId != _user.Id) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } return(ProductServices.Get(userId)); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public void Delete(int id) { try { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } ProductServices.Delete(id); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public void Update(int id, Product product) { try { UserProfile _user = AuthManager.CurrentUser; if (_user == null) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } ProductServices.Update(id, product.Price.Value, product.Quantity); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }
public UserProduct AddToCart(UserProduct product) { try { UserProfile _user = AuthManager.CurrentUser; if (_user == null || product.UserId != _user.Id) { throw ExceptionResponse.Forbidden(Request, Messages.InvalidCredentials); } return(ProductServices.AddToCart(product)); } catch (RequestForbidden ex) { throw ExceptionResponse.Forbidden(Request, ex.Message); } catch (Exception ex) { throw ExceptionResponse.ServerErrorResponse(Request); } }