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"));
        }
Exemple #3
0
        public void Delete(int agentId)
        {
            using (IUnitOfWork unitOfWork = context.CreateUnitOfWork())
            {
                Agent agent = agentRepo.GetById(agentId);

                if (!agentRepo.Delete(agent))
                {
                    throw new FailedOperationException("Failed to delete Agent.", agent);
                }

                unitOfWork.SaveChanges();
            }
        }
Exemple #4
0
        public void DeleteAgent()
        {
            using (var uow = new CapriconContext())
            {
                var agentRep      = new AgentRepository(uow);
                var existingAgent = agentRep.Find(a => a.AgentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingAgent);

                int agentId;
                if (existingAgent != null)
                {
                    agentId = existingAgent.AgentId;

                    agentRep.Delete(existingAgent);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        //Retrieve validation errors
                        ex.EntityValidationErrors.ToList().ForEach
                        (
                            v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                            (
                                e =>
                            {
                                System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                            }
                            );
                        }
                        );
                        Assert.Fail("Test failed");
                    }

                    Assert.IsNull(agentRep.Find(a => a.AgentId == agentId).FirstOrDefault());
                }
                else //no agents were selected
                {
                    Assert.Fail("No agent was selected");
                }
            }
        }
        public void AgentRepositoryTest()
        {
            AgentRepository repository = new AgentRepository();
            Agent expectedAgent = new Agent(repository.GetAll().Count() + 1, "agensomeagent");

            repository.Add(expectedAgent);

            Agent realAgent = repository.GetItem(expectedAgent.id);

            Assert.AreEqual(expectedAgent, realAgent);

            repository.Delete(expectedAgent);

            realAgent = repository.GetItem(expectedAgent.id);

            Assert.AreEqual(null, realAgent);
        }
Exemple #6
0
        public void AgentRepositoryTest()
        {
            AgentRepository repository    = new AgentRepository();
            Agent           expectedAgent = new Agent(repository.GetAll().Count() + 1, "agensomeagent");

            repository.Add(expectedAgent);


            Agent realAgent = repository.GetItem(expectedAgent.id);

            Assert.AreEqual(expectedAgent, realAgent);

            repository.Delete(expectedAgent);


            realAgent = repository.GetItem(expectedAgent.id);

            Assert.AreEqual(null, realAgent);
        }
        public void AgentRepositoryTest()
        {
            AgentRepository repository = new AgentRepository();
            Agent expectedAgent = new Agent
            {
                name = "agensomeagent"
            };

            repository.Add(expectedAgent);

            Agent realAgent = repository.GetAll().Last();

            Assert.AreEqual(expectedAgent.name, realAgent.name);

            repository.Delete(realAgent);

            realAgent = repository.GetAll().Last();

            Assert.AreNotEqual(expectedAgent.name, realAgent.name);
        }
        public void AgentRepositoryTest()
        {
            AgentRepository repository    = new AgentRepository();
            Agent           expectedAgent = new Agent
            {
                name = "agensomeagent"
            };

            repository.Add(expectedAgent);


            Agent realAgent = repository.GetAll().Last();

            Assert.AreEqual(expectedAgent.name, realAgent.name);

            repository.Delete(realAgent);


            realAgent = repository.GetAll().Last();

            Assert.AreNotEqual(expectedAgent.name, realAgent.name);
        }
        public void DeleteingDependencyAndAgentObject()
        {
            Response aResponse = new Response();



            repo.Insert(AGENT1);

            Alias alias = AliasTesting.ALIAS;

            alias.Agent = AGENT1;
            aliasRepo.Insert(alias);



            AgencyAgent agencyAgent = AgencyAgentTesting.AGENCYAGENT1;

            agencyAgent.Agent = AGENT1;
            agencyAgentRepo.Insert(agencyAgent);

            aResponse = repo.Delete(1);

            Assert.IsTrue(aResponse.Success);
        }
        public void DeleteAgent()
        {
            using (var uow = new CapriconContext())
            {
                var agentRep = new AgentRepository(uow);
                var existingAgent = agentRep.Find(a => a.AgentId == 2).FirstOrDefault();

                Assert.IsNotNull(existingAgent);

                int agentId;
                if (existingAgent != null)
                {
                    agentId = existingAgent.AgentId;

                    agentRep.Delete(existingAgent);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        //Retrieve validation errors
                        ex.EntityValidationErrors.ToList().ForEach
                        (
                            v =>
                            {
                                v.ValidationErrors.ToList().ForEach
                                    (
                                        e =>
                                        {
                                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                        }
                                    );
                            }
                        );
                        Assert.Fail("Test failed");
                    }

                    Assert.IsNull(agentRep.Find(a => a.AgentId == agentId).FirstOrDefault());
                }
                else //no agents were selected
                    Assert.Fail("No agent was selected");
            }
        }