// GET: EscalationUsers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EscalationUser  escalationUser = db.EscalationUsers.Find(id);
            List <Category> category       = db.Categories.Where(c => c.EscalationUserId == id).ToList();
            List <int>      categoryids    = new List <int>();

            foreach (Category i in category)
            {
                categoryids.Add(i.Id);
            }
            escalationUser.CategoriesIds = categoryids;
            if (escalationUser == null)
            {
                return(HttpNotFound());
            }

            ViewBag.CostCenterList = db.CostCenters.OrderBy(m => m.CostCenterCode).ToList();
            ViewBag.DepartmentList = db.Departments.Where(m => m.type == Constants.FORWARD).ToList();
            ViewBag.UserList       = db.Users.ToList();
            ViewBag.Categories     = db.Categories.Where(m => m.DepartmentId == escalationUser.DepartmentId && m.FeedBackType.name == Constants.Complaints).ToList();
            ViewBag.Status         = "Delete";
            return(View("CreateList", new EscalationUserViewModel {
                EscalationUser = escalationUser, EscalationUsers = db.EscalationUsers.ToList()
            }));
        }
示例#2
0
        public ApplicationUser getOperationsEscalationUser(int?costCenterId)
        {
            EscalationUser  escUser = db.EscalationUsers.Where(m => m.CostCenterId == costCenterId).FirstOrDefault();
            ApplicationUser user    = db.Users.Find(escUser.firstEscalationUserId);

            return(user);
        }
        public ActionResult Edit(EscalationUser escalationUser)
        {
            if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
            {
                if (escalationUser.CategoriesIds == null)
                {
                    ModelState.AddModelError("add_categories", "Please Add Categories for The Departments other than Operations");
                }
            }
            if (ModelState.IsValid)
            {
                List <Category> categories = db.Categories.Where(c => c.EscalationUserId == escalationUser.Id).ToList();

                if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
                {
                    foreach (Category i in categories)
                    {
                        i.EscalationUserId = null;
                        db.Entry(i).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                    db.Entry(escalationUser).State = EntityState.Modified;
                    db.SaveChanges();
                    foreach (int cid in escalationUser.CategoriesIds)
                    {
                        Category c = db.Categories.Find(cid);
                        c.EscalationUserId = escalationUser.Id;
                        db.Entry(c).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                    TempData["SuccessMsg"] = "Escalation User has been Updated";
                    return(RedirectToAction("Create"));
                }
                else
                {
                    if (userInterface.getEscalationUserCostCentr(escalationUser) <= 0)
                    {
                        db.Entry(escalationUser).State = EntityState.Modified;
                        db.SaveChanges();
                        TempData["SuccessMsg"] = "Escalation User has been Updated";
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        TempData["FailMsg"] = "Cost Center is already assigned to Escalation User";
                    }
                }
            }

            ViewBag.CostCenterList = db.CostCenters.OrderBy(m => m.CostCenterCode).ToList();
            ViewBag.DepartmentList = db.Departments.Where(m => m.type == Constants.FORWARD).ToList();
            ViewBag.UserList       = db.Users.ToList();

            //ViewBag.Categories = db.Categories.Where(c => c.EscalationUserId == null).ToList();
            ViewBag.Status = "Update";
            // return RedirectToAction("CreateList", new EscalationUserViewModel { EscalationUsers = db.EscalationUsers.ToList() });
            return(RedirectToAction("Edit", new { id = escalationUser.Id }));
        }
示例#4
0
        public ApplicationUser getEscalationUser(int?departmentId, int?categoryId)
        {
            var query = from e in db.EscalationUsers
                        join Category in db.Categories on e.Id equals Category.EscalationUserId
                        where e.DepartmentId == departmentId && Category.Id == categoryId
                        select e;
            EscalationUser user = (EscalationUser)query.FirstOrDefault();

            return(db.Users.Find(user.firstEscalationUserId));
        }
示例#5
0
 public int getEscalationUserCostCentr(EscalationUser escalationUser)
 {
     if (escalationUser.Id > 0)
     {
         return(db.EscalationUsers.OrderByDescending(m => m.Id).Where(m => m.CostCenterId == escalationUser.CostCenterId && m.Id != escalationUser.Id).ToList().Count());
     }
     else
     {
         return(db.EscalationUsers.OrderByDescending(m => m.Id).Where(m => m.CostCenterId == escalationUser.CostCenterId).ToList().Count());
     }
 }
        public ActionResult Create(EscalationUser escalationUser)
        {
            if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
            {
                if (escalationUser.CategoriesIds == null)
                {
                    ModelState.AddModelError("add_categories", "Please Add Categories for The Departments other than Operations");
                }
            }
            Debug.WriteLine(ModelState.IsValid + "0-----------------------");
            if (ModelState.IsValid)
            {
                if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
                {
                    db.EscalationUsers.Add(escalationUser);
                    db.SaveChanges();
                    foreach (int cid in escalationUser.CategoriesIds)
                    {
                        Category c = db.Categories.Find(cid);
                        c.EscalationUserId = escalationUser.Id;
                        db.Entry(c).State  = EntityState.Modified;
                        db.SaveChanges();

                        TempData["SuccessMsg"] = "Escalation User Added";
                        return(RedirectToAction("Create"));
                    }
                }
                else
                {
                    if (userInterface.getEscalationUserCostCentr(escalationUser) <= 0)
                    {
                        db.EscalationUsers.Add(escalationUser);
                        db.SaveChanges();
                        TempData["SuccessMsg"] = "Escalation User Added";
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        TempData["FailMsg"] = "Cost Center is already assigned to Escalation User";
                    }
                }
            }
            ViewBag.CostCenterList = db.CostCenters.OrderBy(m => m.CostCenterCode).ToList();
            ViewBag.DepartmentList = db.Departments.Where(m => m.type == Constants.FORWARD).ToList();
            ViewBag.UserList       = db.Users.ToList();
            ViewBag.Categories     = db.Categories.Where(m => m.DepartmentId == escalationUser.DepartmentId && m.FeedBackType.name == Constants.Complaints).ToList();
            ViewBag.Status         = "Add";
            return(View("CreateList", new EscalationUserViewModel {
                EscalationUsers = db.EscalationUsers.ToList()
            }));
        }
        // GET: EscalationUsers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EscalationUser escalationUser = db.EscalationUsers.Find(id);

            if (escalationUser == null)
            {
                return(HttpNotFound());
            }
            return(View(escalationUser));
        }
示例#8
0
        public bool getTicketsOnCategory(int id)
        {
            EscalationUser escUser = db.EscalationUsers.Find(id);

            var categories = db.Categories.Where(c => c.EscalationUserId == (db.EscalationUsers.FirstOrDefault(e => e.firstEscalationUserId == escUser.firstEscalationUserId)).Id).Select(c => c.Id).ToList();;
            int tickets    = db.Feedbacks.Where(f => f.categoryId != null).Where(f => categories.Contains(f.categoryId.Value)).ToList().Count();

            if (tickets > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void deleteEscalationUser(int id)
        {
            List <Category> categories = db.Categories.Where(c => c.EscalationUserId == id).ToList();

            foreach (Category i in categories)
            {
                i.EscalationUserId = null;
                db.Entry(i).State  = EntityState.Modified;
                db.SaveChanges();
            }
            EscalationUser escalationUser = db.EscalationUsers.Find(id);

            db.EscalationUsers.Remove(escalationUser);
            db.SaveChanges();
            TempData["SuccessMsg"] = "Escalation User is deleted Successfully";
        }
示例#10
0
        public ActionResult DeleteConfirmed(int id)
        {
            List <Category> categories = db.Categories.Where(c => c.EscalationUserId == id).ToList();

            foreach (Category i in categories)
            {
                i.EscalationUserId = null;
                db.Entry(i).State  = EntityState.Modified;
                db.SaveChanges();
            }
            EscalationUser escalationUser = db.EscalationUsers.Find(id);

            db.EscalationUsers.Remove(escalationUser);
            db.SaveChanges();
            return(RedirectToAction("Create"));
        }
示例#11
0
        public ActionResult Edit(EscalationUser escalationUser)
        {
            if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
            {
                if (escalationUser.CategoriesIds == null)
                {
                    ModelState.AddModelError("add_categories", "Please Add Categories for The Departments other than Operations");
                }
            }
            if (ModelState.IsValid)
            {
                List <Category> categories = db.Categories.Where(c => c.EscalationUserId == escalationUser.Id).ToList();
                foreach (Category i in categories)
                {
                    i.EscalationUserId = null;
                    db.Entry(i).State  = EntityState.Modified;
                    db.SaveChanges();
                }
                db.Entry(escalationUser).State = EntityState.Modified;
                db.SaveChanges();
                if (!db.Departments.Find(escalationUser.DepartmentId).name.Equals(Constants.OPERATIONS))
                {
                    foreach (int cid in escalationUser.CategoriesIds)
                    {
                        Category c = db.Categories.Find(cid);
                        c.EscalationUserId = escalationUser.Id;
                        db.Entry(c).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Create"));
            }

            ViewBag.CostCenterList = db.CostCenters.OrderBy(m => m.CostCenterCode).ToList();
            ViewBag.DepartmentList = db.Departments.Where(m => m.type == Constants.FORWARD).ToList();
            ViewBag.UserList       = db.Users.ToList();
            //ViewBag.Categories = db.Categories.Where(c => c.EscalationUserId == null).ToList();
            ViewBag.Status = "Update";
            return(View("CreateList", new EscalationUserViewModel {
                EscalationUsers = db.EscalationUsers.ToList()
            }));
        }