Beispiel #1
0
        public async Task <IHttpActionResult> PatchCourse(int id)
        {
            if (!CourseExists(id))
            {
                return(BadRequest());
            }
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(StatusCode(HttpStatusCode.UnsupportedMediaType));
            }

            Course course = db.Courses.Find(id);
            var    filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

            var imageBytes = await filesReadToProvider.Contents[0].ReadAsByteArrayAsync();

            int?oldImageId = Image.ExtractImageId(course.ImageUrl);

            if (oldImageId != null)
            {
                ImageController.DeleteImage(oldImageId.Value, db);
            }
            course.ImageUrl = ImageController.SaveImage(imageBytes, Request, db);

            db.SaveChanges();

            return(Ok(course));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PatchUser()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(StatusCode(HttpStatusCode.UnsupportedMediaType));
            }

            int         userId              = JwtAuthManager.GetUserIdFromRequest(Request);
            UserDetails userDetails         = db.UserDetails.Find(userId);
            var         filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

            var imageBytes = await filesReadToProvider.Contents[0].ReadAsByteArrayAsync();

            int?oldImageId = Image.ExtractImageId(userDetails.ImageUrl);

            if (oldImageId != null)
            {
                ImageController.DeleteImage(oldImageId.Value, db);
            }

            userDetails.ImageUrl = ImageController.SaveImage(imageBytes, Request, db);

            db.SaveChanges();

            return(Ok(userDetails));
        }
Beispiel #3
0
        public HttpResponseMessage PostDeactivateAccount(UserDTO userDTO)
        {
            string email = JwtAuthManager.GetEmailFromRequest(Request);

            if (CheckCredentials(email, userDTO.Password))
            {
                int  userId = JwtAuthManager.GetUserIdFromRequest(Request);
                User user   = db.Users.Find(userId);

                List <Comment> allComments = db.Comments.Where(c => c.UserDetails.UserDetailsId == userId).ToList();
                allComments.ForEach(c => db.Comments.Remove(c));

                int?imageId = Image.ExtractImageId(user.UserDetails.ImageUrl);

                if (imageId != null)
                {
                    ImageController.DeleteImage(imageId.Value, db);
                }

                db.UserDetails.Remove(user.UserDetails);

                db.Users.Remove(user);

                db.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Профилот не е деактивиран бидејќи лозинката која ја внесовте е погрешна."));
        }
Beispiel #4
0
        // DELETE: api/Courses/5
        public IHttpActionResult DeleteCourse(int id)
        {
            Course course = db.Courses.Find(id);

            if (course != null)
            {
                int?oldImageId = Image.ExtractImageId(course.ImageUrl);
                if (oldImageId != null)
                {
                    ImageController.DeleteImage(oldImageId.Value, db);
                }
                db.Courses.Remove(course);
                db.SaveChanges();
            }
            return(Ok());
        }