public ActionResult Edit(int id)
        {
            DeveloperStudio studioToEdit = this.unitOfWork.DeveloperStudio.GetById(id);

            this.ViewBag.Games = this.unitOfWork.Game.GetAll().ToList();
            return(this.View(studioToEdit));
        }
        private void UpdateNonMtoMProperties(DeveloperStudio updatedDeveloperStudio)
        {
            DeveloperStudio oldDeveloperStudio = this.unitOfWork.DeveloperStudio.GetById(updatedDeveloperStudio.ID);

            oldDeveloperStudio.Name         = updatedDeveloperStudio.Name;
            oldDeveloperStudio.Foundingdate = updatedDeveloperStudio.Foundingdate;
        }
        private void UpdateGames(DeveloperStudio updatedDeveloperStudio, int[] games)
        {
            DeveloperStudio oldDeveloperStudio = this.unitOfWork.DeveloperStudio.GetById(updatedDeveloperStudio.ID);

            oldDeveloperStudio.Game.ToList().ForEach(p => oldDeveloperStudio.Game.Remove(p));
            foreach (int gameId in games)
            {
                oldDeveloperStudio.Game.Add(this.unitOfWork.Game.GetById(gameId));
            }
        }
        public ActionResult Create(DeveloperStudio newStudio, FormCollection collection)
        {
            if (!collection.AllKeys.Contains("Games"))
            {
                this.ModelState.AddModelError("Game", "Please select at least one Game");
            }
            else
            {
                int[] gameIDs = Array.ConvertAll(collection["Games"].Split(','), int.Parse);
                gameIDs.ForEach(id => newStudio.Game.Add(this.unitOfWork.Game.GetById(id)));
                this.unitOfWork.DeveloperStudio.Add(newStudio);
                this.unitOfWork.Complete();
                this.ViewBag.Message = "Developer Studio was created";
            }

            this.ViewBag.Games = this.unitOfWork.Game.GetAll().ToList();
            return(this.View(newStudio));
        }
        public ActionResult Edit(DeveloperStudio editedStudio, FormCollection collection)
        {
            if (!collection.AllKeys.Contains("Games"))
            {
                this.ModelState.AddModelError("Game", "Please select at least one Game");
            }
            else
            {
                int[] gameIDs = Array.ConvertAll(collection["Games"].Split(','), int.Parse);
                this.UpdateNonMtoMProperties(editedStudio);
                this.UpdateGames(editedStudio, gameIDs);
                this.unitOfWork.Complete();
                this.ViewBag.Message = "Saved";
            }

            this.ViewBag.Games = this.unitOfWork.Game.GetAll().ToList();
            return(this.View(this.unitOfWork.DeveloperStudio.GetById(editedStudio.ID)));
        }