Ejemplo n.º 1
0
        public IActionResult Create([FromBody] JObject review)
        {
            using (var context = new RevojiDataContext())
            {
                DBReview dbReview = new DBReview(review);

                if (dbReview.DBReviewable == null)
                {
                    return(BadRequest(new { ErrorMessage = "Reviewable not populated." }));
                }

                // If there is no reviewable in the db that the review refers to then create one
                if (dbReview.ReviewableId == 0 &&
                    dbReview.DBReviewable.TpId != null &&
                    !context.Reviewables.Any(r => r.TpId == dbReview.DBReviewable.TpId))
                {
                    //DBReviewable dBReviewable = new DBReviewable(reviewable);
                    context.Add(dbReview.DBReviewable);
                    context.Save();

                    dbReview.ReviewableId = dbReview.DBReviewable.Id;
                }

                dbReview.DBAppUser    = null;
                dbReview.DBReviewable = null;

                context.Add(dbReview);
                context.Save();

                var result = new Review(dbReview);
                return(Ok(result));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Create([FromBody] JObject appUser)
        {
            using (var context = new RevojiDataContext())
            {
                try
                {
                    DBAppUser dbAppUser = new DBAppUser(appUser);

                    if (context.AppUsers.Any(user => user.Handle == dbAppUser.Handle))
                    {
                        return(BadRequest("duplicate_user_handle"));
                    }

                    if (context.AppUsers.Any(user => user.Email == dbAppUser.Email))
                    {
                        return(BadRequest("duplicate_user_email"));
                    }

                    if (string.IsNullOrEmpty(dbAppUser.Password))// TODO: handle things like #chars, capital/lower case, symbols?
                    {
                        return(BadRequest("password_not_set"));
                    }

                    context.Add(dbAppUser);
                    context.Save();

                    return(Ok(new AppUserDetail(dbAppUser)));
                }
                catch (DbUpdateException e)
                {
                    return(BadRequest("invalid_error")); //TODO: should be an object
                }
            }
        }
        public IActionResult uploadProfilePicture([FromForm] IFormFile file)
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(ApiUser.ID);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                var result = AWSFileUploader.UploadObject(file, "profile_pictures").Result;

                if (!result.Success)
                {
                    return(new BadRequestResult());
                }

                var content = JsonConvert.DeserializeObject <AppUserContent>(dbAppUser.Content);
                content.Avatar = result.Url;

                dbAppUser.Content = JsonConvert.SerializeObject(content);
                context.Save();

                return(Ok(result));
            }
        }
Ejemplo n.º 4
0
        public IActionResult CreateReply([FromBody] JObject reply)
        {
            using (var context = new RevojiDataContext())
            {
                DBReply dBReply = new DBReply(reply);

                context.Add(dBReply);
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 5
0
        public IActionResult CreateLike([FromBody] JObject like)
        {
            using (var context = new RevojiDataContext())
            {
                DBLike dBLike = new DBLike(like);

                context.Add(dBLike);
                context.Save();

                return(Ok(new Like(dBLike)));
            }
        }
        public IActionResult Create([FromBody] ReviewableDetail reviewable)
        {
            using (var context = new RevojiDataContext())
            {
                DBReviewable dbReviewable = new DBReviewable();
                reviewable.UpdateDB(dbReviewable);

                context.Add(dbReviewable);
                context.Save();

                return(Ok(new Reviewable(dbReviewable)));
            }
        }
Ejemplo n.º 7
0
        public IActionResult CreateBookmark([FromBody] JObject bookmark)
        {
            using (var context = new RevojiDataContext())
            {
                DBBookmark dBBookmark = new DBBookmark(bookmark);
                dBBookmark.Created = DateTime.Now;

                context.Add(dBBookmark);
                context.Save();

                return(Ok(new Bookmark(dBBookmark)));
            }
        }
Ejemplo n.º 8
0
        public IActionResult AddFollowing(int followingId)
        {
            using (var context = new RevojiDataContext())
            {
                DBFollowing dbFollowing = new DBFollowing();
                dbFollowing.FollowingAppUserId = followingId;
                dbFollowing.FollowerAppUserId  = ApiUser.ID;

                context.Add(dbFollowing);
                context.Save();

                return(Ok(new AppUserFollowing(dbFollowing)));
            }
        }
Ejemplo n.º 9
0
        public IActionResult BlockUser(int blockedId)
        {
            using (var context = new RevojiDataContext())
            {
                DBBlocking dBBlocking = new DBBlocking();
                dBBlocking.BlockedAppUserId = blockedId;//TODO: check if user actually exists
                dBBlocking.BlockerAppUserId = ApiUser.ID;

                context.Add(dBBlocking);
                context.Save();

                return(Ok(new AppUserBlocking(dBBlocking)));
            }
        }
Ejemplo n.º 10
0
        public IActionResult SetSettings(int id, [FromBody] JObject appUserSettings)
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(id);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                dbAppUser.Settings = JsonConvert.SerializeObject(appUserSettings);
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 11
0
        public IActionResult Update(int id, [FromBody] JObject appUser)
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(id);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                dbAppUser.update(appUser);
                context.Save();

                return(Ok(new AppUserDetail(dbAppUser)));
            }
        }
Ejemplo n.º 12
0
        public IActionResult Delete()
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(ApiUser.ID);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                context.Remove(dbAppUser);
                context.Save();

                return(Ok());
            }
        }
        public IActionResult Delete(int id)
        {
            using (var context = new RevojiDataContext())
            {
                DBReviewable dbReviewable = context.Get <DBReviewable>(id);
                if (dbReviewable == null)
                {
                    return(new NotFoundResult());
                }

                context.Remove(dbReviewable);
                context.Save();

                return(Ok());
            }
        }
        public IActionResult Update(int id, [FromBody] JObject reviewable)
        {
            using (var context = new RevojiDataContext())
            {
                DBReviewable dbReviewable = context.Get <DBReviewable>(id);
                if (dbReviewable == null)
                {
                    return(new NotFoundResult());
                }

                dbReviewable.update(reviewable);
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 15
0
        public IActionResult SetInfo(int id, [FromBody] JObject reviewableInfo)
        {
            using (var context = new RevojiDataContext())
            {
                DBReviewable dbReviewable = context.Get <DBReviewable>(id);
                if (dbReviewable == null)
                {
                    return(new NotFoundResult());
                }

                dbReviewable.Content = JsonConvert.SerializeObject(reviewableInfo);
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 16
0
        public IActionResult DeleteLike(int id, int appUserId)
        {
            using (var context = new RevojiDataContext())
            {
                DBLike dBLike = context.Likes
                                .Where(l => l.ReviewId == id &&
                                       l.AppUserId == appUserId)
                                .FirstOrDefault();
                if (dBLike == null)
                {
                    return(new NotFoundResult());
                }

                context.Remove(dBLike);
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 17
0
        public IActionResult CreateNotification([FromBody] JObject notification)
        {
            using (var context = new RevojiDataContext())
            {
                DBNotification dBNotification = new DBNotification(notification);

                if (dBNotification.AppUserId == -1)
                {
                    return(BadRequest("app_user_id_required"));
                }

                dBNotification.Created = DateTime.Now;

                context.Add(dBNotification);
                context.Save();

                return(Ok(new Notification(dBNotification)));
            }
        }
Ejemplo n.º 18
0
        public IActionResult RemoveFollowing(int followingId)
        {
            using (var context = new RevojiDataContext())
            {
                var dbFollowing = context.Followings
                                  .Where(f => f.FollowerAppUserId == ApiUser.ID &&
                                         f.FollowingAppUserId == followingId)
                                  .FirstOrDefault();

                if (dbFollowing == null)
                {
                    return(new NotFoundResult());
                }

                context.Remove(dbFollowing);
                context.Save();

                return(Ok(new AppUserFollowing(dbFollowing)));
            }
        }
Ejemplo n.º 19
0
        public IActionResult UnblockUser(int blockedId)
        {
            using (var context = new RevojiDataContext())
            {
                var dBBlocking = context.Blockings
                                 .Where(f => f.BlockerAppUserId == ApiUser.ID &&
                                        f.BlockedAppUserId == blockedId)
                                 .FirstOrDefault();

                if (dBBlocking == null)
                {
                    return(new NotFoundResult());
                }

                context.Remove(dBBlocking);
                context.Save();

                return(Ok(new AppUserBlocking(dBBlocking)));
            }
        }
Ejemplo n.º 20
0
        public IActionResult ChangeEmail(string email)
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(ApiUser.ID);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                //if (email is valid)
                //{
                //    return new BadRequestResult();
                //}

                dbAppUser.Email = email;
                context.Save();

                return(Ok());
            }
        }
Ejemplo n.º 21
0
        public IActionResult ChangePassword(string newPassword, string oldPassword)
        {
            using (var context = new RevojiDataContext())
            {
                DBAppUser dbAppUser = context.Get <DBAppUser>(ApiUser.ID);
                if (dbAppUser == null)
                {
                    return(new NotFoundResult());
                }

                if (!dbAppUser.isPasswordCorrect(oldPassword))
                {
                    return(new UnprocessableEntityResult());
                }

                dbAppUser.SetPassword(newPassword);
                context.Save();

                return(Ok());
            }
        }