//public ActionResult Edit([Bind(Include = "ID,Name,Description,CreatedBy,CreatedDate,StartDate,ExpectedEndDate,ActualEndDate,ProductBacklogID,ScrumMasterID")] ReleaseBacklog releaseBacklog, string[] selectedUserStories)
        public ActionResult Edit(int?id, string[] selectedUserStories, string ScrumMasterList)
        {
            ReleaseBacklog releaseBacklog = db.ReleaseBacklogs
                                            .Include(r => r.UserStories)
                                            .Where(r => r.ID == id)
                                            .Single();

            if (ModelState.IsValid)
            {
                UpdateReleaseBacklogUserStories(selectedUserStories, releaseBacklog);

                if (ScrumMasterList != "")
                {
                    releaseBacklog.EmployeeID = int.Parse(ScrumMasterList);
                    ////hr interface method has to be given here
                    //var emp = db.Employees.Find(int.Parse(ScrumMasterList));
                    //emp.Role = Role.ScrumMaster;
                    //emp.ReleaseBacklogs.Add(releaseBacklog);
                    HRInterface hr = new clsHRFacade();
                    hr.AssignScrumMaster(int.Parse(ScrumMasterList), releaseBacklog, db);
                }
                else
                {
                    //var emp = db.Employees.Find(releaseBacklog.EmployeeID);

                    //if (emp != null)
                    //{
                    //    if (emp.ReleaseBacklogs.Count == 1)
                    //    {
                    //        emp.Role = null;
                    //    }
                    //    emp.ReleaseBacklogs.Remove(releaseBacklog);
                    //}

                    HRInterface hr = new clsHRFacade();
                    hr.RemoveScrumMasterRole(releaseBacklog, db);

                    releaseBacklog.EmployeeID = null;
                    ////hr interface method has to be given here
                }

                db.Entry(releaseBacklog).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductBacklogID = new SelectList(db.ProductBacklogs, "ID", "Name", releaseBacklog.ProductBacklogID);

            PopulateAssignedUserStories(releaseBacklog);
            return(View(releaseBacklog));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Description,CreatedBy,CreatedDate,StartDate,ExpectedEndDate,ActualEndDate,ProductBacklogID,EmployeeID")] ReleaseBacklog releaseBacklog, string[] selectedUserStories, string ScrumMasterList)
        {
            if (selectedUserStories != null)
            {
                releaseBacklog.UserStories = new List <UserStory>();

                foreach (var userStory in selectedUserStories)
                {
                    var userStoryToAdd = db.UserStories.Find(int.Parse(userStory));
                    releaseBacklog.UserStories.Add(userStoryToAdd);
                }
            }

            if (ScrumMasterList != "")
            {
                releaseBacklog.EmployeeID = int.Parse(ScrumMasterList);

                ////hr interface method has to be given here
                //var emp = db.Employees.Find(int.Parse(ScrumMasterList));
                //emp.Role = Role.ScrumMaster;
                //emp.ReleaseBacklogs.Add(releaseBacklog);

                HRInterface hr = new clsHRFacade();
                hr.AssignScrumMaster(int.Parse(ScrumMasterList), releaseBacklog, db);
            }

            releaseBacklog.CreatedBy   = 1;
            releaseBacklog.CreatedDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.ReleaseBacklogs.Add(releaseBacklog);

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            PopulateAssignedUserStories(releaseBacklog);

            ViewBag.ProductBacklogID = new SelectList(db.ProductBacklogs, "ID", "Name", releaseBacklog.ProductBacklogID);
            return(View(releaseBacklog));
        }