コード例 #1
0
        public ActionResult createHeadline(headlineViewModel model, HttpPostedFileBase headlineHeader)
        {
            bool hasError = false;
            if(model.fileSummary == "" || model.fileSummary == null)
            {
                ModelState.AddModelError("", "The file summary is required");
                hasError = true;
            }
            if (model.headlinev.numberOfUsers < 1)
            {
                ModelState.AddModelError("", "The number of users needs to a real number");
                hasError = true;
            }
            if (model.headlinev.numberOfUsers > 25)
            {
                ModelState.AddModelError("", "The maximum number of users at one time is 25");
                hasError = true;
            }
            if (User.Identity.IsAuthenticated == false)
            {
                ModelState.AddModelError("", "You must be logged in to change this");
                hasError = true;
            }
            string annotateError = uHline.checkAnnotation(headlineHeader, model.fileTypeDefined);
            if (annotateError != "")
            {
                hasError = true;
                ModelState.AddModelError("", annotateError);
            }
            if (hasError)
            {
                return View(new headlineViewModel());
            }
            if (ModelState.IsValid && hasError == false)
            {
                if ((from title in user.headlines
                     where title.title == model.headlinev.title
                     select title).Count() >= 1)
                {
                    ModelState.AddModelError("", "Try the title again");
                    return View(new headlineViewModel());
                }

                else
                {
                    try
                    {                        
                        headlineView newHeadline = new headlineView
                        {
                            numberOfUsers = model.headlinev.numberOfUsers,
                            followingCount = 1,
                            title = model.headlinev.title,
                            accessLevel = model.headlinev.accessLevel,
                            adminId = (from usershere in user.UserProfiles
                                       where usershere.UserId == WebSecurity.CurrentUserId
                                       select usershere).FirstOrDefault(),
                        };
                        user.headlines.Add(newHeadline);
                        string description = model.fileDescription;
                        if (model.fileTypeDefined == 1)
                        {
                            model.fileDescription = files.updateImage(headlineHeader, model.headlinev.title, "HeadlineHeader");
                            //files.updateImage(headlineHeader, model.headlinev.title, "HeadlineHeader");
                            description = "image";
                        }

                        var personConnectingDefined = (from users in user.UserProfiles
                                                       where users.UserId == WebSecurity.CurrentUserId
                                                       select users).FirstOrDefault();
                        var permissionDefined = (from perms in user.permissions
                                                 where perms.ID < 4
                                                 where perms.ID > 0
                                                 orderby perms.ID ascending
                                                 select perms).ToList();
                        user.SaveChanges();
                        foreach (var item in permissionDefined)
                        {
                            var newGroup = new group
                            {
                                forPeople = false,
                                groupName = model.headlinev.title + item.permissionName,
                            };
                            var sourceDefined = (from headlines in user.headlines
                                                 where headlines.title == model.headlinev.title
                                                 select headlines.headlineDefinedId).First();
                            user.SaveChanges();
                            user.permissionsToGroup.Add(
                            new permissionToGroup
                                {
                                    defineGroup = newGroup,
                                    defineSource = "Headline",
                                    permissionDefined = item,
                                    sourceID = sourceDefined,
                                    personConnecting = personConnectingDefined
                                });
                        }
                        var followingPerson = (from users in user.UserProfiles
                                               join user2 in user.userDefinition
                                               on users equals user2.usernameFK
                                               where users.UserId == WebSecurity.CurrentUserId
                                               select user2).First();
                        followingPerson.following += 1;
                        user.highlightsComputedMessages.Add(new highlightsComputedMessage
                        {
                            createdUserID = WebSecurity.CurrentUserId,
                            sourceDefinition = model.headlinev.title,
                            highlightID = (from highlights in user.highlightsPerType
                                           where highlights.highlightMethod == "headlineCreate"
                                           select highlights).First()
                        });
                        user.headlineToUsers.Add(
                           new headlineToUser
                           {
                               personID = (from ytu in user.UserProfiles
                                           where ytu.UserId == WebSecurity.CurrentUserId
                                           select ytu).FirstOrDefault(),
                               headlineID = (from headlines in user.headlines
                                             where headlines.title == model.headlinev.title
                                             orderby headlines.headlineDefinedId
                                             select headlines).First(),
                           });
                        user.SaveChanges();
                        uHline.addAnnotation(model.fileDescription, model.fileTypeDefined, newHeadline, model.fileSummary);

                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", e.Message.ToString());
                        return View(new headlineViewModel());
                    }
                    return Redirect("/headlines/editHeadline/" + model.headlinev.title);
                }
            }
            else
            {
                ModelState.AddModelError("", "Unknown error");
                return View(new headlineViewModel());
            }
        }
コード例 #2
0
        public ActionResult editHeadline(headlineView model, string id, HttpPostedFileBase headlineHeader)
        {
            var thistitle = model.title;
            if (User.Identity.IsAuthenticated == false)
            {
                ModelState.AddModelError("editHeadline", "You must be logged in to change this");
                return Redirect("/headlines/editHeadline/" + thistitle);
            }
            if (WebSecurity.CurrentUserId != (from headlines in user.headlines
                                              where headlines.title == id
                                              select headlines.adminId.UserId).FirstOrDefault())
            {
                ModelState.AddModelError("editHeadline", "You are not authenticated to make a change here, please contact"
                    + WebSecurity.CurrentUserName + "to gain access to the group");
                return Redirect("/headlines/editHeadline/" + thistitle);
            }

            using (var db = new UsersContext())
            {
                files.updateImage(headlineHeader, id, "HeadlineHeader");
                headlineView headlineToEdit = db.headlines.FirstOrDefault(m => m.title == id);
                headlineToEdit.title = thistitle;
                headlineToEdit.accessLevel = model.accessLevel;
                db.SaveChanges();
            }
            return Redirect("/headlines/editHeadline/" + thistitle);
        }
コード例 #3
0
        public PartialViewResult _joinedStatus(headlineView model)
        {
            var backgroundColor = mem.getSetting("backgroundColor");
            var highlightColor = mem.getSetting("fontColor");
            ViewBag.styling = "border-width:0px;color:" + highlightColor + ";background-color:" + backgroundColor + "";
            ViewBag.title = model.title;
            var title = model.title;
            //}
            var joined = (from headlines in user.headlineToUsers
                          where headlines.headlineID.title == title
                          where headlines.personID.UserId == WebSecurity.CurrentUserId
                          select headlines).Count();
            if (User.Identity.IsAuthenticated == false)
            {
                //They cannot join, they shouldn't have got it anyway, but I don't want them seeing an error
                return PartialView("_joinedStatus");
            }
            else
            {
                headlineView headlinecount = user.headlines.FirstOrDefault(m => m.title == title);
                List<string> permsGranted = new List<string>();
                permsGranted.Add("view");
                if (headlinecount.accessLevel > 1)
                {
                    permsGranted.Add("edit");
                }
                if (headlinecount.accessLevel > 2)
                {
                    permsGranted.Add("insert");
                }
                if (joined == 0)
                {

                    headlinecount.followingCount = headlinecount.followingCount + 1;
                    userDefinition usercount = user.userDefinition.FirstOrDefault
                        (m => m.usernameFK.UserId == WebSecurity.CurrentUserId);
                    usercount.joinedNumber = usercount.joinedNumber + 1;
                    foreach (var permission in permsGranted)
                    {
                        permissionToGroup permToAdd = new permissionToGroup
                        {
                            sourceID = (from headlines in user.headlines
                                        where headlines.title == model.title
                                        select headlines.headlineDefinedId).FirstOrDefault(),
                            defineSource = "Headline",
                            defineGroup = (from groups in user.groups
                                           where groups.groupName == title + permission
                                           select groups).FirstOrDefault(),
                            permissionDefined = (from perms in user.permissions
                                                 where perms.permissionName == permission
                                                 select perms).FirstOrDefault(),
                            personConnecting = (from users in user.UserProfiles
                                                where users.UserId == WebSecurity.CurrentUserId
                                                select users).FirstOrDefault()
                        };


                        user.permissionsToGroup.Add(permToAdd);
                    }
                    headlineToUser userToAdd = new headlineToUser
                        {
                            personID = (from ytu in user.UserProfiles
                                        where ytu.UserId == WebSecurity.CurrentUserId
                                        select ytu).FirstOrDefault(),
                            headlineID = (from ytu in user.headlines
                                          where ytu.title == title
                                          select ytu).FirstOrDefault(),
                        };
                    user.headlineToUsers.Add(userToAdd);

                    user.SaveChanges();
                    ViewBag.yourStatus = headlineq.getCountLink(title);
                    return PartialView("_joinedStatus");
                }
                else
                {
                    headlinecount.followingCount = headlinecount.followingCount - 1;
                    userDefinition usercount = user.userDefinition.FirstOrDefault(m => m.usernameFK.UserId == WebSecurity.CurrentUserId);
                    usercount.joinedNumber = usercount.joinedNumber - 1;
                    headlineToUser headlineshere = (from huse in user.headlineToUsers
                                                    where huse.headlineID.title == title
                                                    where huse.personID.UserId == WebSecurity.CurrentUserId
                                                    select huse).First();
                    user.headlineToUsers.Remove(headlineshere);
                    int nullcountheadline = user.headlineToUsers.Count(m => m.headlineToUserID == null);
                    int nullcountperson = user.headlineToUsers.Count(m => m.personID == null);
                    if (nullcountperson + nullcountheadline > 0)
                    {
                        headlineToUser headlinestoremove = user.headlineToUsers.FirstOrDefault(m => m.headlineID.headlineDefinedId == null || m.personID.UserId == null);
                        user.headlineToUsers.Remove(headlinestoremove);
                    }
                    foreach (var item in permsGranted)
                    {
                        permissionToGroup groupRemove = user.permissionsToGroup.FirstOrDefault(m => m.personConnecting ==
                            (from users in user.UserProfiles
                             where users.UserId == WebSecurity.CurrentUserId
                             select users).FirstOrDefault() && m.sourceID ==
                             (from headlines in user.headlines
                              where headlines.title == title
                              select headlines.headlineDefinedId).FirstOrDefault()
                              && m.permissionDefined.permissionName == item);
                        user.permissionsToGroup.Remove(groupRemove);
                    }
                    user.SaveChanges();
                    ViewBag.yourStatus = headlineq.getCountLink(title);
                    return PartialView("_joinedStatus");
                    //m => m.personID.UserId == WebSecurity.CurrentUserId
                }
            }
            //The user is not authenticated and the count to join is failing here, this is unreachable           
        }
コード例 #4
0
        public ActionResult viewHeadline(headlineView model, string id)
        {
            int permissionCount = headlineq.permissionCount(id, "view");

            ViewBag.Title = id;
            ViewBag.headlineTitle = id;
            if (permissionCount == 0)
            {
                ViewBag.viewerror = "You do not have permission to view, though you might be able to edit";
            }
            else
            {
                ViewBag.viewerror = "";
            }
            ViewBag.yourStatus = headlineq.getCountLink(model.title);
            if (id == "" || id == null)
            {
                return RedirectToAction("searchHeadlines", "Headlines");
            }
            ViewBag.headlineTags = getTags(id);

            return View();


        }