Ejemplo n.º 1
0
        public Agent Add(Agent agent)
        {
            using (IUnitOfWork unitOfWork = context.CreateUnitOfWork())
            {
                int newAgentId = agentRepo.Insert(agent);
                if (newAgentId <= 0)
                {
                    throw new FailedOperationException("Failed to insert Agent.", agent);
                }

                unitOfWork.SaveChanges();
                return(agentRepo.GetById(newAgentId));
            }
        }
 public ActionResult Edit(int agentId)
 {
     AgentRepository repository = new AgentRepository();
     var agent = repository.GetById(agentId);
     var agentToEdit = new EditAgent { agentId = agent.id, agentName = agent.name };
     return View(agentToEdit);
 }
 public ActionResult Delete(int agentId)
 {
     AgentRepository repository = new AgentRepository();
     var agentToDelete = repository.GetById(agentId);
     repository.Delete(agentToDelete);
     return RedirectToAction("Index");
 }
        public ActionResult Delete(int agentId)
        {
            AgentRepository repository    = new AgentRepository();
            var             agentToDelete = repository.GetById(agentId);

            repository.Delete(agentToDelete);
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int agentId)
        {
            AgentRepository repository  = new AgentRepository();
            var             agent       = repository.GetById(agentId);
            var             agentToEdit = new EditAgent {
                agentId = agent.id, agentName = agent.name
            };

            return(View(agentToEdit));
        }
        public ActionResult Edit(int agentId, EditAgent agent)
        {
            AgentRepository repository = new AgentRepository();

            Agents agentToUpdate = new Agents
            {
                id        = agent.agentId,
                Contracts = repository.GetById(agentId).Contracts,
                name      = agent.agentName
            };

            repository.Update(agentToUpdate);
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int agentId, EditAgent agent)
        {
            AgentRepository repository = new AgentRepository();

            Agents agentToUpdate = new Agents
            {
                id = agent.agentId,
                Contracts = repository.GetById(agentId).Contracts,
                name = agent.agentName
            };

            repository.Update(agentToUpdate);
            return RedirectToAction("Index");
        }