Example #1
0
        public ActionResult Create([Bind(Include = "Name")] CreateTeamViewModel model)
        {
            if (ModelState.IsValid)
            {
                var team = new Team
                {
                    TeamId = Guid.NewGuid(),
                    Name   = model.Name
                };

                try
                {
                    db.Teams.Add(team);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(View("Error", new HandleErrorInfo(ex, "Teams", "Index")));
                }

                return(RedirectToAction("Index"));
            }
            // Something failed, return
            return(View(model));
        }
Example #2
0
        public Owner Create(Owner owner)
        {
            owner.Id = Guid.NewGuid();
            _context.Add(owner);
            _context.SaveChanges();

            return(owner);
        }
        public ActionResult Create([Bind(Include = "Name, TeamIds")] CreatePlayerViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Instantiate our new player with only the Id and Name properties
                Player player = new Player
                {
                    PlayerId = Guid.NewGuid(),
                    Name     = model.Name
                };

                if (model.TeamIds != null)
                {
                    foreach (var id in model.TeamIds)
                    {
                        // Convert the id to a Guid from a string
                        var teamId = Guid.Parse(id);
                        // Retrieve team from database...
                        var team = db.Teams.Find(teamId);
                        // ... and add it to the player's Team collection
                        try
                        {
                            player.Teams.Add(team);
                        }
                        catch (Exception ex)
                        {
                            return(View("Error", new HandleErrorInfo(ex, "Players", "Index")));
                        }
                    }
                }
                // Add new Player to db & save changes
                try
                {
                    db.Players.Add(player);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(View("Error", new HandleErrorInfo(ex, "Players", "Index")));
                }

                // If successful, return
                return(RedirectToAction("Details", new { id = player.PlayerId }));
            }
            else
            {
                ModelState.AddModelError("", "Something failed.");
                return(View(model));
            }
        }
Example #4
0
        public ActionResult Contact(Contact contact)
        {
            if (ModelState.IsValid)
            {
                using (var db = new appDbContext())
                {
                    contact.CreateDate = DateTime.Now;
                    contact.CreatedBy  = User.Identity.Name;
                    contact.UpdateDate = DateTime.Now;
                    contact.UpdatedBy  = User.Identity.Name;

                    db.Contacts.Add(contact);
                    db.SaveChanges();
                    Session["StatusMessage"] = "Kişi formu başarıyla kaydedildi";
                    return(RedirectToAction("Index"));
                }
            }
            return(View(contact));
        }