public ActionResult Contact()
        {
            ViewBag.Message = "Contact ODU's Spring 2017 CS411W Red Team";
            var usr           = User.Identity.GetUserId();
            var vm            = new ViolationViewModel();
            var db            = new CPPdatabaseEntities();
            var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
            var sessions      =
                db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId)
                .Select(session => session.CallSenderId)
                .ToList();

            sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId));

            foreach (var partnerId in sessions)
            {
                //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single());
                vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO()
                {
                    Email    = x.AspNetUser.Email,
                    Id       = x.AspNetUser.Id,
                    UserName = x.AspNetUser.UserName
                }).Single());
            }
            var withoutDupes = vm.List.GroupBy(user => user.Email).Select(group => group.First());

            vm.List = withoutDupes.ToList();
            ViewData["ViolationList"] = vm.List;
            //ViewData["userIsAdmin"] = db.CppUsers.Where(x => x.AspNetUserId == usr).Select(x => x.PermissionLevel).Single() == 1;
            ViewBag.ListItems       = vm.List;
            ViewData["userIsAdmin"] = db.CppUsers.Single(x => x.Id == thisCppUserId).PermissionLevel == 1;
            return(View());
        }
        // GET: Violation
        public ActionResult Index()
        {
            var vm            = new ViolationViewModel();
            var db            = new CPPdatabaseEntities();
            var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
            var sessions      =
                db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId)
                .Select(session => session.CallSenderId)
                .ToList();

            sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId));

            foreach (var partnerId in sessions)
            {
                //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single());
                vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO()
                {
                    Email    = x.AspNetUser.Email,
                    Id       = x.AspNetUser.Id,
                    UserName = x.AspNetUser.UserName
                }).Single());
            }

            return(View(vm));
        }
        public ActionResult SendEmailRequest()
        {
            var aspNetUserId   = User.Identity.GetUserId();
            var sessionId      = Request["sessionId"];
            var recipientemail = Request["recipientEmail"];

            MessageService.SendEmailRequest(User.Identity.GetUserName(), recipientemail, sessionId);

            var senderId    = db.CppUsers.Where(u => u.AspNetUser.Id == aspNetUserId).Select(u => u.Id).Single();
            var recipientId = db.CppUsers.Where(u => u.AspNetUser.Email == recipientemail).Select(u => u.Id).Single();

            //SessionService.BeginSessionLog(senderId, recipientId); //Shouldn't begin session until they click link


            var            contactOwnerId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
            List <Contact> contactList;

            try
            {
                contactList = ContactService.GetContactList(contactOwnerId, db).ToList();
            }
            catch (Exception eIndexContactList)
            {
                return(View("Error", new HandleErrorInfo(eIndexContactList, "Call", "Index")));
            }

            var profileList = new List <Profile>();

            profileList.AddRange(
                contactList.Select(contact => db.Profiles.FirstOrDefault(prof => prof.CppUserId == contact.ContactListMemberId)));


            return(View("Index", profileList));
        }
        // GET: Call
        public ActionResult Index()
        {
            try
            {
                var            contactOwnerId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
                List <Contact> contactList;

                try
                {
                    contactList = ContactService.GetContactList(contactOwnerId, db).ToList();
                }
                catch (Exception eIndexContactList)
                {
                    return(View("Error", new HandleErrorInfo(eIndexContactList, "Call", "Index")));
                }
                var profileList = new List <Profile>();
                profileList.AddRange(
                    contactList.Select(contact => db.Profiles.FirstOrDefault(prof => prof.CppUserId == contact.ContactListMemberId)));

                return(View(profileList));
            }
            catch (Exception eIndex)
            {
                return(View("Error", new HandleErrorInfo(eIndex, "Call", "Index")));
            }
        }
示例#5
0
        public ActionResult Create([Bind(Include = "Id,RaterId,RatedUserId,Comment,InterestingScore,ComprehensibleScore,PolitenessScore")] Rating rating)
        {
            //check in session log table to see if two users ever had a session
            //if not, rating cannot be created

            if (ModelState.IsValid)
            {
                //store raterId
                var raterIdToStore = CppUserService.GetCppUserId(User.Identity.GetUserId(), mDB);
                var ratedIdToStore = rating.RatedUserId;

                //raterId must not equal ratedUserId
                if (raterIdToStore.Equals(ratedIdToStore))
                {
                    Exception eCreate = new Exception("RatedUserId == RaterId");
                    return(View("Error", new HandleErrorInfo(eCreate, "Ratings", "Create")));
                }

                //if this particular rater-ratee combination exists
                //then remove that rating first to replace it with a new rating
                if (ratingExists(ratedIdToStore))
                {
                    var toRemove = (from r in mDB.Ratings
                                    where
                                    r.RaterId == raterIdToStore && r.RatedUserId == ratedIdToStore
                                    select new
                    {
                        r.Id
                    }).FirstOrDefault();

                    DeleteConfirmed(toRemove.Id);
                }

                rating.RaterId = raterIdToStore;
                rating.RaterId = raterIdToStore;

                //compute average rating from user input
                decimal average;
                average             = (rating.InterestingScore + rating.ComprehensibleScore + rating.PolitenessScore) / (decimal)3;
                rating.AverageScore = average;

                mDB.Ratings.Add(rating);
                mDB.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.RatedUserId = new SelectList(mDB.CppUsers, "Id", "AspNetUserId", rating.RatedUserId);
            return(View(rating));
        }
示例#6
0
        /*
         * returns true if a rating already exists between two users
         * users passed as Id parameters
         */
        public bool ratingExists(int ratedId)
        {
            int raterId = CppUserService.GetCppUserId(User.Identity.GetUserId(), mDB);

            var pastRatings = mDB.Ratings.Where(b => b.RaterId == raterId);

            foreach (var r1 in pastRatings.ToList())
            {
                if (r1.RatedUserId == ratedId)
                {
                    return(true);
                }
            }

            return(false);
        }