public async void SetStoryItem(InstaStoryItem storyItem)
        {
            Visibility = Visibility.Visible;
            await Task.Delay(420);

            StoryVM.SetStoryItem(storyItem, MainLV?.FindScrollViewer());
        }
Пример #2
0
        private void ConvertStoryVM(ref Story story, StoryVM storyVM)
        {
            storyVM.Slug = SlugUtil.GenerateSlug(storyVM.StoryName);

            story.StoryName        = storyVM.StoryName;
            story.StoryProgress    = storyVM.StoryProgress;
            story.StoryStatus      = storyVM.StoryStatus;
            story.StoryDescription = storyVM.StoryDescription;
            story.AuthorId         = storyVM.Author.AuthorId;
            story.Author           = db.Authors.Find(storyVM.Author.AuthorId);
            story.CreatedDate      = storyVM.CreatedDate;
            story.LastEditedDate   = storyVM.LastEditedDate;
            story.UserId           = storyVM.UserId;
            story.Score            = storyVM.Score;
            story.RateCount        = storyVM.RateCount;
            story.Image            = storyVM.Image;
            story.Slug             = storyVM.Slug;

            var slugCount = db.Stories.Count(s => s.Slug.StartsWith(storyVM.Slug));

            if (slugCount > 0)
            {
                story.Slug += slugCount;
            }
        }
        public int AddStory(StoryVM storyVM)
        {
            Story story = new Story
            {
                StoryId       = storyVM.StoryId,
                CategoryId    = storyVM.CategoryId,
                IntimacyId    = storyVM.IntimacyId,
                Title         = storyVM.Title,
                Content       = storyVM.Content,
                HashtagWord   = storyVM.HashtagWord,
                Picture       = storyVM.Picture,
                NoView        = storyVM.NoView,
                ApproveStatus = "P",
                UserId        = storyVM.UserId,

                Category = GetCategoryById(storyVM.CategoryId),
                Intimacy = GetIntimacyById(storyVM.IntimacyId),

                Hashtags = storyVM.Hashtags
            };

            _ctx.Stories.Add(story);
            _ctx.SaveChanges();

            AddHashtagByStory(story);
            return(_ctx.Stories.Max(s => s.StoryId));
        }
Пример #4
0
        public bool UpdateStory(StoryVM storyVM)
        {
            Story story = new Story
            {
                StoryId       = storyVM.StoryId,
                CategoryId    = storyVM.CategoryId,
                IntimacyId    = storyVM.IntimacyId,
                Title         = storyVM.Title,
                Content       = storyVM.Content,
                HashtagWord   = storyVM.HashtagWord,
                Picture       = storyVM.Picture,
                NoView        = storyVM.NoView,
                ApproveStatus = "P",
                UserId        = storyVM.UserId,

                Category = GetCategoryById(storyVM.CategoryId),
                Intimacy = GetIntimacyById(storyVM.IntimacyId),

                Hashtags = storyVM.Hashtags
            };

            _stories.RemoveAll(s => s.StoryId == story.StoryId);
            _stories.Add(story);
            return(true);
        }
Пример #5
0
        public int AddStory(StoryVM storyVM)
        {
            if (_stories.Count <= 0)
            {
                storyVM.StoryId = 1;
            }
            else
            {
                storyVM.StoryId = _stories.Max(c => c.StoryId) + 1;
            }
            Story story = new Story
            {
                StoryId       = storyVM.StoryId,
                CategoryId    = storyVM.CategoryId,
                IntimacyId    = storyVM.IntimacyId,
                Title         = storyVM.Title,
                Content       = storyVM.Content,
                HashtagWord   = storyVM.HashtagWord,
                Picture       = storyVM.Picture,
                NoView        = storyVM.NoView,
                ApproveStatus = "P",
                UserId        = storyVM.UserId,

                Category = GetCategoryById(storyVM.CategoryId),
                Intimacy = GetIntimacyById(storyVM.IntimacyId),

                Hashtags = storyVM.Hashtags
            };

            _stories.Add(story);
            return(story.StoryId);
        }
        public bool UpdateStory(StoryVM storyVM)
        {
            Story story = new Story
            {
                StoryId       = storyVM.StoryId,
                CategoryId    = storyVM.CategoryId,
                IntimacyId    = storyVM.IntimacyId,
                Title         = storyVM.Title,
                Content       = storyVM.Content,
                HashtagWord   = storyVM.HashtagWord,
                Picture       = storyVM.Picture,
                NoView        = storyVM.NoView,
                ApproveStatus = "P",
                UserId        = storyVM.UserId,

                Category = GetCategoryById(storyVM.CategoryId),
                Intimacy = GetIntimacyById(storyVM.IntimacyId),

                Hashtags = storyVM.Hashtags
            };

            _ctx.Entry(story).State = System.Data.Entity.EntityState.Modified;
            story.Hashtags.Clear();
            _ctx.SaveChanges();

            return(AddHashtagByStory(story));
        }
Пример #7
0
        public async Task <IHttpActionResult> PostStory(StoryVM storyVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Story story = new Story();

            ConvertStoryVM(ref story, storyVM);
            foreach (var genreVM in storyVM.Genres)
            {
                Genre genre = await db.Genres.FindAsync(genreVM.GenreId);

                story.Genres.Add(genre);
            }

            db.Stories.Add(story);
            await db.SaveChangesAsync().ConfigureAwait(false);

            //db.SaveChanges();

            storyVM.Update(story);

            return(CreatedAtRoute("NameApi", new { slug = storyVM.Slug }, storyVM));
        }
Пример #8
0
        public ActionResult Edit(int storyId)
        {
            StoryVM model = _repo.GetStoryVMById(storyId);

            model.SetCategoryItems(_repo.GetCategoryList());
            model.SetIntimacyItems(_repo.GetIntimacyList());
            return(View(model));
        }
Пример #9
0
        public ActionResult CreateStory()
        {
            StoryVM story = new StoryVM();

            story.Created  = DateTime.Now;
            story.Modified = DateTime.Now;
            return(View());
        }
Пример #10
0
        public ActionResult Add()
        {
            StoryVM model = new StoryVM();

            model.UserId = CurrentUser.User.Id;
            model.SetCategoryItems(_repo.GetCategoryList());
            model.SetIntimacyItems(_repo.GetIntimacyList());
            return(View(model));
        }
Пример #11
0
 public ActionResult Delete(StoryVM model)
 {
     if (_repo.DeleteStory(model.StoryId))
     {
         return(RedirectToAction("List", "Story"));
     }
     else
     {
         ModelState.AddModelError("Story", "Cannot delete story");
         return(View(model));
     }
 }
Пример #12
0
        public IHttpActionResult GetStory(int id)
        {
            Story story = db.Stories.Find(id);

            if (story == null)
            {
                return(NotFound());
            }
            StoryVM storyVM = new StoryVM(story);

            return(Ok(storyVM));
        }
Пример #13
0
        // GET: api/Stories
        public IQueryable <StoryVM> GetStories()
        {
            List <StoryVM> storyVMs = new List <StoryVM>();
            StoryVM        storyVM;

            foreach (var story in db.Stories.Where(s => s.StoryStatus == 1))
            {
                storyVM = new StoryVM(story);
                storyVMs.Add(storyVM);
            }

            return(storyVMs.AsQueryable());
        }
Пример #14
0
        public async void SetStoryItem(InstaStoryItem storyItem)
        {
            ShowGrid(true);
            Visibility = Visibility.Visible;
            InsightsButton.Visibility = UserHelper.IsBusiness ? Visibility.Visible : Visibility.Collapsed;
            await Task.Delay(420);

            StoryVM.SetStoryItem(storyItem, MainLV?.FindScrollViewer());
            if (UserHelper.IsBusiness)
            {
                StoryInsightUc.SetItem(storyItem);
            }
        }
Пример #15
0
        // GET: api/Stories/name/N
        public IQueryable <StoryVM> GetStoryByName(string slug)
        {
            IQueryable <Story> stories  = db.Stories.Where(s => s.Slug.Equals(slug));
            List <StoryVM>     storyVMs = new List <StoryVM>();
            StoryVM            storyVM;

            foreach (var story in stories)
            {
                storyVM = new StoryVM(story);
                storyVMs.Add(storyVM);
            }

            return(storyVMs.AsQueryable());
        }
Пример #16
0
 public ActionResult Add(StoryVM model)
 {
     if (ModelState.IsValid)
     {
         if (_repo.AddStory(model) > 0)
         {
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("Story", "Cannot add new story");
         }
     }
     return(View(model));
 }
Пример #17
0
 public ActionResult Edit(StoryVM model)
 {
     if (ModelState.IsValid)
     {
         if (_repo.UpdateStory(model))
         {
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("Story", "Cannot edit story");
         }
     }
     return(View(model));
 }
Пример #18
0
        public async Task <IHttpActionResult> PutStory(int id, StoryVM storyVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != storyVM.StoryId)
            {
                return(BadRequest());
            }

            Story story = db.Stories.Find(id);

            ConvertStoryVM(ref story, storyVM);
            foreach (var genreVM in storyVM.Genres)
            {
                Genre genre = await db.Genres.FindAsync(genreVM.GenreId);

                story.Genres.Add(genre);
            }

            db.Entry(story).State = EntityState.Modified;

            try
            {
                //db.SaveChanges();
                await db.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            storyVM.Update(story);

            return(StatusCode(HttpStatusCode.OK));
        }
Пример #19
0
        public async Task <ActionResult> AddStory(StoryVM story)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_AjaxValidation", "Required story fields were not filled in."));
            }

            if (story.Type == Core.Enums.StoryType.GivingAdvice && !userService.IsInRole(StandardRoles.Coach))
            {
                ModelState.AddModelError("Type", "You cannot give an advice because you are not a coach.");
                return(PartialView("_AjaxValidation", "You are not allowed to create this type of story."));
            }

            var user = await userProfileUOW.UserProfiles.GetUserProfileAsync(userService.GetUserId());

            if (user.BannedUntil > DateTime.Now)
            {
                ModelState.AddModelError("UserBanned", "You have been banned so you cannot post a story.");
                return(PartialView("_AjaxValidation", "Could not post story."));
            }

            var storyModel = Mapper.Map <Story>(story);

            if (storyModel.GroupId.HasValue)
            {
                var group = await storyUOW.Groups.GetGroupByIdAsync(storyModel.GroupId.Value);

                storyModel.Group = group;
            }
            storyModel.State  = Core.Models.ModelState.Added;
            storyModel.Date   = DateTime.Now;
            storyModel.UserId = userService.GetUserId();

            storyUOW.Stories.InsertOrUpdate(storyModel);

            var hashtags = storyService.ExtractHashtags(storyModel);
            await storyUOW.Hashtags.UpdateHashtags(hashtags);

            await storyUOW.CompleteAsync();

            return(RedirectToAction("Index"));
            //return Redirect(Request.UrlReferrer.AbsolutePath);
        }
Пример #20
0
        public IHttpActionResult DeleteStory(int id)
        {
            Story story = db.Stories.Find(id);

            if (story == null)
            {
                return(NotFound());
            }

            //db.Stories.Remove(story);
            story.StoryStatus = -1;
            story.Chapters.ForEach(c => c.ChapterStatus = -1);
            db.Entry(story).State = EntityState.Modified;
            db.SaveChanges();

            StoryVM storyVM = new StoryVM(story);

            return(Ok(storyVM));
        }
Пример #21
0
        public ActionResult AddStory(StoryVM storyVM)
        {
            StoryManager sm = new StoryManager();

            int UserID = (int)Session["ActiveUser"];

            if (storyVM != null)
            {
                if (Directory.Exists(Server.MapPath("~/files")) == false)
                {
                    Directory.CreateDirectory(Server.MapPath("~/files"));
                }

                string path = (Path.Combine(Server.MapPath("~/files"), storyVM.file.FileName));
                storyVM.file.SaveAs(path);
                sm.InsertStory(path, storyVM.StoryComment, UserID);
                return(RedirectToAction("HomePage"));
            }

            return(View());
        }
Пример #22
0
        public ActionResult Approve(StoryVM model, string Save, string Denied)
        {
            if (!string.IsNullOrEmpty(Save))
            {
                _repo.ApproveStory(model.StoryId, model.Feedback);
            }
            else
            {
                if (!string.IsNullOrEmpty(model.Feedback))
                {
                    _repo.DenyStory(model.StoryId, model.Feedback);
                }
                else
                {
                    ModelState.AddModelError("Feedback", "Feedback is require");
                    return(RedirectToAction("ViewStory", new { id = model.StoryId }));
                }
            }

            return(RedirectToAction("Index"));
        }
Пример #23
0
        //get stories
        public PartialViewResult _Stories(short id)
        {
            var stories = db.Stories.Where(r => r.IsAboutId == id).ToList();

            List <StoryVM> model = new List <StoryVM>();

            foreach (Story story in stories)
            {
                List <Tag> tags = (from st in db.StoryTags
                                   join t in db.Tags on st.TagId equals t.TagId
                                   where st.StoryId == story.StoryId
                                   select t
                                   )
                                  .ToList()
                ;
                StoryVM toAdd = new StoryVM {
                    Story = story, Tags = tags
                };
                model.Add(toAdd);
            }

            return(PartialView(model));
        }
        public Story ConvertVMToStory(StoryVM storyVM)
        {
            Story story = new Story
            {
                StoryId       = storyVM.StoryId,
                CategoryId    = storyVM.CategoryId,
                IntimacyId    = storyVM.IntimacyId,
                Title         = storyVM.Title,
                Content       = storyVM.Content,
                HashtagWord   = storyVM.HashtagWord,
                Picture       = storyVM.Picture,
                NoView        = storyVM.NoView,
                ApproveStatus = storyVM.ApproveStatus,
                UserId        = storyVM.UserId,

                Category = GetCategoryById(storyVM.CategoryId),
                Intimacy = GetIntimacyById(storyVM.IntimacyId),

                Hashtags = storyVM.Hashtags
            };

            return(story);
        }
        public StoryVM ConvertStoryToVM(Story story)
        {
            StoryVM storyVM = new StoryVM
            {
                StoryId       = story.StoryId,
                CategoryId    = story.CategoryId,
                IntimacyId    = story.IntimacyId,
                Title         = story.Title,
                Content       = story.Content,
                HashtagWord   = story.HashtagWord,
                Picture       = story.Picture,
                NoView        = story.NoView,
                ApproveStatus = story.ApproveStatus,
                UserId        = story.UserId,

                Category = GetCategoryById(story.CategoryId),
                Intimacy = GetIntimacyById(story.IntimacyId),
                User     = GetUserById(story.UserId),
                Hashtags = story.Hashtags
            };

            return(storyVM);
        }
Пример #26
0
        public async Task <ActionResult> EditStory(int storyId, StoryVM story)
        {
            var existentStory = await storyUOW.Stories.GetStoryById(storyId);

            if (existentStory == null)
            {
                ModelState.AddModelError("storyId", "The story that you want to edit does not exist.");
                return(PartialView("_AjaxValidation", ""));
            }

            if (existentStory.UserId != userService.GetUserId())
            {
                ModelState.AddModelError("storyId", "You do not have the rights to edit that story.");
                return(PartialView("_AjaxValidation", ""));
            }

            if (existentStory.Type != story.Type)
            {
                existentStory.Type = story.Type;
            }
            if (!string.IsNullOrEmpty(story.Title) && existentStory.Title != story.Title)
            {
                existentStory.Title = story.Title;
            }
            if (!string.IsNullOrEmpty(story.Content) && existentStory.Content != story.Content)
            {
                existentStory.Content = story.Content;
            }

            existentStory.State = Core.Models.ModelState.Modified;

            storyUOW.Stories.InsertOrUpdate(existentStory);

            await storyUOW.CompleteAsync();

            return(RedirectToAction("Index"));
        }
Пример #27
0
 public ActionResult DeleteStory(StoryVM story)
 {
     StoryDAL.DeleteStory(Mapper.Map <StoryDM>(story));
     return(View());
 }
Пример #28
0
        public ActionResult Delete(int storyId)
        {
            StoryVM model = _repo.GetStoryVMById(storyId);

            return(View(model));
        }