public HttpResponseMessage EditUserImage(int id)
        {
            try
            {
                using (logic)
                {
                    string fileName = Guid.NewGuid() + ".jpg";
                    string fullPath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName);


                    using (FileStream stream = new FileStream(fullPath, FileMode.Create))
                    {
                        HttpContext.Current.Request.InputStream.CopyTo(stream); // This will save the file
                    }

                    UsersDTO updatedUser = logic.EditPicture(id, fileName);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
 public HttpResponseMessage DeleteUser(int id)
 {
     try
     {
         using (logic)
         {
             logic.DeleteUser(id);
             return(Request.CreateResponse(HttpStatusCode.NoContent));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(
                    HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
        public HttpResponseMessage DeleteUserImage(int id)
        {
            try
            {
                using (logic)
                {
                    UsersDTO updatedUser = logic.EditPicture(id, null);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
        public HttpResponseMessage EditPassword(int id, UsersDTO user)
        {
            try
            {
                using (logic)
                {
                    user.id = id;

                    UsersDTO updatedUser = logic.EditPassword(user);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
 public HttpResponseMessage AddUser(UsersDTO user)
 {
     try
     {
         using (logic)
         {
             UsersDTO addedUser = logic.AddUser(user);
             return(Request.CreateResponse(HttpStatusCode.Created, addedUser));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
 public HttpResponseMessage GetAllUsers()
 {
     try
     {
         using (logic)
         {
             List <UsersDTO> allUsers = logic.GetAllUsers();
             return(Request.CreateResponse(HttpStatusCode.OK, allUsers));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
Пример #7
0
 public HttpResponseMessage UpdateModels(ModelsDTO givenModel, int id)
 {
     try
     {
         using (logic)
         {
             givenModel.id = id;
             ModelsDTO updatedModel = logic.UpdateModel(givenModel);
             if (updatedModel == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
             return(Request.CreateResponse(HttpStatusCode.OK, updatedModel));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
Пример #8
0
 public HttpResponseMessage AddModel(ModelsDTO givenModel)
 {
     try
     {
         using (logic)
         {
             ModelsDTO addedModel = logic.AddModel(givenModel);
             return(Request.CreateResponse(HttpStatusCode.Created, addedModel));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
 public HttpResponseMessage UpdateDesign(DesignsDTO givenDesign, int id)
 {
     try
     {
         using (logic)
         {
             givenDesign.id = id;
             DesignsDTO updatedDesign = logic.UpdateDesign(givenDesign);
             if (updatedDesign == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
             return(Request.CreateResponse(HttpStatusCode.OK, updatedDesign));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }