Exemple #1
0
        public PartialViewResult DisplayUpdates(int id)
        {
            var Updates = Mapper.Map <IEnumerable <Update>, IEnumerable <UpdateViewModel> >(updateService.GetUpdatesByGoal(id));

            foreach (var item in Updates)
            {
                item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
            }
            UpdateListViewModel updates = new UpdateListViewModel()
            {
                Updates = Updates,
                Metric  = goalService.GetGoal(id).Metric,
                Target  = goalService.GetGoal(id).Target,
                // IsSupported =  updateSupportService.IsUpdateSupported(,((SocialGoalUser)(User.Identity)).UserId)
            };

            return(PartialView("_UpdateView", updates));
        }
        public ActionResult SaveUpdate(UpdateFormModel newupdate)
        {
            // Update update = Mapper.Map<UpdateFormModel, Update>(newupdate);
            if (ModelState.IsValid)
            {
                Update update = Mapper.Map <UpdateFormModel, Update>(newupdate);
                update.Goal = goalService.GetGoal(newupdate.GoalId);
                var updateVal = updateService.GetHighestUpdateValue(newupdate.GoalId);

                if (updateVal != null)
                {
                    if (updateVal.status <= newupdate.status)
                    {
                        updateService.CreateUpdate(update);
                    }
                    else
                    {
                        update.status = -1;
                        ModelState.AddModelError(update.Updatemsg, "cannot enter");
                    }
                }
                else
                {
                    updateService.CreateUpdate(update);
                }


                var Updates = Mapper.Map <IEnumerable <Update>, IEnumerable <UpdateViewModel> >(updateService.GetUpdatesByGoal(newupdate.GoalId));
                foreach (var item in Updates)
                {
                    item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
                }
                UpdateListViewModel updates = new UpdateListViewModel()
                {
                    Updates = Updates,
                    Metric  = goalService.GetGoal(newupdate.GoalId).Metric,
                    Target  = goalService.GetGoal(newupdate.GoalId).Target,
                    //IsSupported = updateSupportService.IsUpdateSupported(newupdate.UpdateId,((SocialGoalUser)(User.Identity)).UserId)
                };
                return(PartialView("_UpdateView", updates));
            }
            return(null);
        }
Exemple #3
0
        public ActionResult EditUpdate(UpdateFormModel newupdate)
        {
            Update update = Mapper.Map <UpdateFormModel, Update>(newupdate);

            if (ModelState.IsValid)
            {
                update.Goal = goalService.GetGoal(newupdate.GoalId);
                updateService.EditUpdate(update);
                var Updates = Mapper.Map <IEnumerable <Update>, IEnumerable <UpdateViewModel> >(updateService.GetUpdatesByGoal(newupdate.GoalId));
                foreach (var item in Updates)
                {
                    item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
                }
                UpdateListViewModel updates = new UpdateListViewModel()
                {
                    Updates = Updates,
                    Metric  = goalService.GetGoal(newupdate.GoalId).Metric,
                    Target  = goalService.GetGoal(newupdate.GoalId).Target
                };
                return(PartialView("_UpdateView", updates));
            }
            return(null);
        }
        public async Task <UpdateListViewModel> GetRelevantUpdatesAsViewModelAsync(string userId)
        {
            var updates = await this.GetRelevantUpdates(userId);

            var updatesViewModel = new UpdateListViewModel();

            if (updates.Any())
            {
                foreach (var update in updates)
                {
                    if (update.Type == 1)
                    {
                        if (update.UpdateContent == "Watched")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.WatchedContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                        else if (update.UpdateContent == "Watching")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.WatchingContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                        else if (update.UpdateContent == "WantToWatch")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.WantToWatchContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                    }
                    else if (update.Type == 2)
                    {
                        if (update.UpdateContent == "Read")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.ReadContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                        else if (update.UpdateContent == "Reading")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.ReadingContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                        else if (update.UpdateContent == "WantToRead")
                        {
                            updatesViewModel.SeriesUpdates.
                            Add(new SeriesUpdateViewModel
                            {
                                SeriesId        = update.ContentId,
                                Content         = string.Format(SeriesUpdateViewModel.WantToReadContentString, update.UserDisplayName, update.ContentTitle),
                                UpdateId        = update.Id,
                                UserId          = update.UserId,
                                UserDisplayName = update.UserDisplayName,
                            });
                        }
                    }
                    else if (update.Type == 3)
                    {
                        var group = this.groupRepo.AllAsNoTracking().Where(x => x.Id == update.GroupId).FirstOrDefault();
                        updatesViewModel.PostUpdates.
                        Add(new PostUpdateViewModel
                        {
                            UserDisplayName = update.UserDisplayName,
                            Content         = string.Format(PostUpdateViewModel.PostContentTemplate, update.UserDisplayName, update.UpdateContent, group.Name),
                            GroupName       = group.Name,
                            PostId          = update.ContentId,
                            UpdateId        = update.Id,
                        });
                    }
                }
            }

            return(updatesViewModel);
        }