Esempio n. 1
0
        public ActionResult AddBranch(int agentId = 0)
        {
            try
            {
                var agent = dbContext.Agents.Find(agentId);

                if (agent == null)
                {
                    return HttpNotFound();
                }
                else
                {
                    var branch = new AgentBranch() { AgentId = agentId };

                    ViewBag.parishes = dbContext.Parishes.OrderBy(p => p.Name);

                    ViewBag.Agent = agent;
                    return View(branch);
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex.GetBaseException());
                return RedirectToAction("Error", "Default", null);
            }
        }
Esempio n. 2
0
        public ActionResult AddBranch(AgentBranch model)
        {
            try
            {
                var agent = dbContext.Agents.Find(model.AgentId);

                if (agent == null)
                {
                    return HttpNotFound();
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        dbContext.AgentBranches.Add(model);

                        dbContext.SaveChanges();

                        return RedirectToAction("ViewBranch", new { branchId = model.BranchId });
                    }
                    else
                    {
                        ViewBag.parishes = dbContext.Parishes.OrderBy(p => p.Name);
                        ViewBag.Agent = agent;
                        return View(model);
                    }
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex.GetBaseException());
                return RedirectToAction("Error", "Default", null);
            }
        }
Esempio n. 3
0
        public ActionResult EditBranch(AgentBranch model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    dbContext.Entry(model).State = EntityState.Modified;

                    dbContext.SaveChanges();

                    return RedirectToAction("ViewBranch", new { branchId = model.BranchId });
                }
                else
                {
                    ViewBag.parishes = dbContext.Parishes.OrderBy(p => p.Name);
                    return View(model);
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex.GetBaseException());
                return RedirectToAction("Error", "Default", null);
            }
        }