public ActionResult AssignTeamMember(AssistantManagerToMemberViewModel relation)
        {
            try
            {
                var assistangManagerAsssigned = db.AssistantManagerToMemberRelations.Where(x => x.AssistantManagerId == relation.AssistantManagerId && x.TeamMemberId == null).FirstOrDefault();

                bool value = db.AssistantManagerToMemberRelations.Any(x => x.AssistantManagerId == relation.AssistantManagerId && x.TeamMemberId == relation.TeamMemberId);
                AssistantManagerToMemberRelation amr = new AssistantManagerToMemberRelation();

                if (assistangManagerAsssigned != null)
                {
                    assistangManagerAsssigned.TeamMemberId = relation.TeamMemberId;
                }
                else if (value != true)
                {
                    amr.AssistantManagerId = relation.AssistantManagerId;
                    amr.TeamMemberId       = relation.TeamMemberId;
                    db.AssistantManagerToMemberRelations.Add(amr);
                }

                db.SaveChanges();
                return(RedirectToAction("AssistantManagerIndex"));
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }
        public ActionResult DeleteTeamMember(AssistantManagerToMemberViewModel relation)
        {
            AssistantManagerToMemberRelation am = db.AssistantManagerToMemberRelations.Where(u => u.AssistantManagerId == relation.AssistantManagerId && u.TeamMemberId == relation.TeamMemberId).FirstOrDefault();

            if (am != null)
            {
                db.AssistantManagerToMemberRelations.Remove(am);
            }
            db.SaveChanges();

            return(RedirectToAction("AssistantManagerIndex"));
        }
        public ActionResult DeleteTeamMember(string assistantManagerEmail)
        {
            var teamMemberList = db.AssistantManagerToMemberRelations.Include("teamMemberDetails").Where(m => m.assistantManagerDetails.Email == assistantManagerEmail).ToList();
            List <SelectListItem>             teamMembers = new List <SelectListItem>();
            AssistantManagerToMemberViewModel mr          = new AssistantManagerToMemberViewModel();

            foreach (var item in teamMemberList)
            {
                teamMembers.Add(new SelectListItem
                {
                    Text  = item.teamMemberDetails.FirstName,
                    Value = item.TeamMemberId
                });
            }

            ViewBag.teamMembersList = teamMembers;
            mr.AssistantManagerName = db.Users.Where(u => u.Email == assistantManagerEmail).Select(n => n.FirstName).FirstOrDefault();
            mr.AssistantManagerId   = db.Users.Where(u => u.Email == assistantManagerEmail).Select(i => i.Id).FirstOrDefault();

            return(PartialView("DeleteTeamMemberPartial", mr));
        }
        public ActionResult AssignTeamMember(string assistantManagerEmail)
        {
            var teamMemberList = db.Users.Where(u => u.UserType == 3).ToList();
            List <SelectListItem>             TeamMemberList = new List <SelectListItem>();
            AssistantManagerToMemberViewModel mr             = new AssistantManagerToMemberViewModel();

            foreach (var item in teamMemberList)
            {
                TeamMemberList.Add(new SelectListItem
                {
                    Text  = item.FirstName,
                    Value = item.Id
                });
            }

            mr.AssistantManagerName = db.Users.Where(u => u.Email == assistantManagerEmail).Select(n => n.FirstName).FirstOrDefault();
            ViewBag.teammember      = TeamMemberList;
            mr.AssistantManagerId   = db.Users.Where(u => u.Email == assistantManagerEmail).Select(i => i.Id).FirstOrDefault();

            return(PartialView("AssignMemberToAM", mr));
        }