コード例 #1
0
        public ActionResult SendAlertToSubPOST(SendAlertToSubViewModel model, string sub_username)
        {
            //Populate Username
            ViewBag.SubordinateUsername = sub_username;

            if (ModelState.IsValid)
            {
                //Get logged in user id
                var LoggedInId = User.Identity.GetUserId();

                //Get Subordinate
                var Subordinate = _context.Users.SingleOrDefault(n => n.UserName.Equals(sub_username));

                //Check if exists
                if (Subordinate == null)
                {
                    TempData["ErrorMessage"] = "Sorry, the user you attempted to access doesn't exist";
                    return(RedirectToAction("Index"));
                }

                //Check if actually a subordinate
                var ManagerEmployee = _context.ManagerEmployee.SingleOrDefault(n => n.ManagerUserId.Equals(LoggedInId) && n.SubUserId.Equals(Subordinate.Id));
                if (ManagerEmployee == null)
                {
                    TempData["ErrorMessage"] = "Sorry, you are not authorised to access this user";
                    return(RedirectToAction("Index"));
                }

                //Create alert
                var Alert = new Alert()
                {
                    FromUserId            = LoggedInId,
                    ToUserId              = Subordinate.Id,
                    ToGroupId             = null,
                    Text                  = model.Text,
                    AssociatedCallRef     = null,
                    AssociatedKnowledgeId = null,
                    Created               = DateTime.Now,
                    DismissedByUserId     = null,
                    DismissedWhen         = null
                };

                //Save alert
                _context.Alert.Add(Alert);
                _context.SaveChanges();

                //State success
                TempData["SuccessMessage"] = "Alert sent to " + Subordinate.UserName;
                return(RedirectToAction("ViewSubordinate", new { sub_username = Subordinate.UserName }));
            }

            //Failed validation so return view
            return(View("SendAlertToSub", model));
        }
コード例 #2
0
        public ActionResult SendAlertToSubGET(string sub_username)
        {
            //Handle Messages
            HandleMessages();

            //Get logged in user id
            var LoggedInId = User.Identity.GetUserId();

            //Get Subordinate
            var Subordinate = _context.Users.SingleOrDefault(n => n.UserName.Equals(sub_username));

            //Check if exists
            if (Subordinate == null)
            {
                TempData["ErrorMessage"] = "Sorry, the user you attempted to access doesn't exist";
                return(RedirectToAction("Index"));
            }

            //Check if actually a subordinate
            var ManagerEmployee = _context.ManagerEmployee.SingleOrDefault(n => n.ManagerUserId.Equals(LoggedInId) && n.SubUserId.Equals(Subordinate.Id));

            if (ManagerEmployee == null)
            {
                TempData["ErrorMessage"] = "Sorry, you are not authorised to access this user";
                return(RedirectToAction("Index"));
            }

            //Populate Username
            ViewBag.SubordinateUsername = sub_username;

            //Populate data
            SendAlertToSubViewModel model = new SendAlertToSubViewModel()
            {
                ToUsername = Subordinate.UserName
            };

            //Return view
            return(View("SendAlertToSub", model));
        }