Esempio n. 1
0
        public PartialViewResult RateImage(IFormCollection collection, ImageAction action)
        {
            var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId"));

            action.Action     = "Rating";
            action.ActionDate = DateTime.Now;
            action.AppUserId  = signedInUserId;
            action.OwnerId    = signedInUserId;
            action.ImageId    = Convert.ToInt64(collection["ImageId"]);
            action.Rating     = Convert.ToInt64(collection["rating"]);
            action.ClientId   = new AppConfig().ClientId;
            if (_databaseConnection.ImageActions
                .Where(n => n.ImageId == action.ImageId && n.AppUserId == action.AppUserId).ToList().Count <= 0)
            {
                _databaseConnection.Add(action);
                _databaseConnection.SaveChanges();
            }
            var image        = _databaseConnection.Images.SingleOrDefault(n => n.ImageId == action.ImageId);
            var appTransport = new AppTransport
            {
                AppUsers     = _users,
                Images       = _databaseConnection.Images.ToList(),
                ImageActions = _databaseConnection.ImageActions.ToList(),
                Image        = image,
                AppUser      = _users.SingleOrDefault(n => n.AppUserId == signedInUserId)
            };

            return(PartialView("Partials/_PartialRating", appTransport));
        }
Esempio n. 2
0
        public async Task <JsonResult> SaveImageAction([FromBody] ImageAction action)
        {
            var actionExist =
                _databaseConnection.ImageActions.Where(
                    n => n.AppUserId == action.AppUserId && n.ImageId == action.ImageId).ToList();

            if (actionExist.Count <= 0)
            {
                _databaseConnection.Add(action);
                _databaseConnection.SaveChanges();
                var image = _databaseConnection.Images.SingleOrDefault(n => n.ImageId == action.ImageId);
                if (image != null)
                {
                    var notification = new PushNotification
                    {
                        AppUserId        = action.OwnerId,
                        CreatedBy        = action.AppUserId,
                        LastModifiedBy   = action.AppUserId,
                        DateLastModified = DateTime.Now,
                        DateCreated      = DateTime.Now,
                        Category         = SystemNotificationCategory.Comment.ToString(),
                        Read             = false,
                        ControllerId     = image.ImageId,
                        ClientId         = 4
                    };

                    var singleOrDefault = new AppUserFactory()
                                          .GetAllUsers(new AppConfig().FetchUsersUrl).Result
                                          .SingleOrDefault(n => n.AppUserId == image.AppUserId);
                    if (singleOrDefault != null)
                    {
                        notification.Message = singleOrDefault.Name +
                                               " Rated your Image";
                    }
                    await new AppUserFactory().SavePushNotification(new AppConfig().SavePushNotifications, notification);
                }
            }
            return(Json(action));
        }