Esempio n. 1
0
        public bool Update(Client client)
        {
            try
            {
                _context.Clients.Attach(client);

                foreach (var project in client.Projects)
                {
                    if (_context.Projects.Any(p => p.Id == project.Id))
                    {
                        _context.Projects.Attach(project);
                        _context.Entry(project).State = System.Data.EntityState.Modified;
                        //_context.SaveChanges();
                    }
                    else
                    {
                        _context.Projects.Add(project);
                        _context.Entry(project).State = System.Data.EntityState.Added;
                    }
                }

                _context.Entry(client).State = System.Data.EntityState.Modified;

                if (_context.SaveChanges() == 0)
                    return false;

            }
            catch (Exception ex)
            {
                //logger.ErrorFormat("Exception: {0}", ex.ToString());
                return false;
            }

            return true;
        }
Esempio n. 2
0
 public void SaveTest()
 {
     ClientManager target = new ClientManager();
     Client client = new Client{ Id = Guid.NewGuid(), Name = "Qwest", Projects = new List<Project>{new Project{ Id = Guid.NewGuid(), Name = "Connect"}}};
     bool expected = true; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.Create(client);
     Assert.AreEqual(expected, actual);
 }
Esempio n. 3
0
        public void GetTest()
        {
            var manager = new ClientManager();
            var client = new Client { Id = Guid.NewGuid(), Name = "Qwest", Projects = new List<Project> { new Project { Id = Guid.NewGuid(), Name = "Connect" } } };
            manager.Create(client);

            var clientCreated = manager.Get(client.Id);
            Assert.IsNotNull(clientCreated);
            Assert.AreEqual(clientCreated.Id, client.Id);
        }
Esempio n. 4
0
        public void GetAllTest()
        {
            var manager = new ClientManager();
            var client = new Client { Id = Guid.NewGuid(), Name = "Qwest", Projects = new List<Project> { new Project { Id = Guid.NewGuid(), Name = "Connect" } } };
            manager.Create(client);

            var clients = manager.GetAll();
            Assert.IsNotNull(clients);
            Assert.IsTrue(clients.Count() > 0);
        }
Esempio n. 5
0
        public bool Create(Client client)
        {
            try
            {
                _context.Clients.Add(client);
                if (_context.SaveChanges() == 0)
                    return false;
            }
            catch (Exception ex)
            {
                //logger.ErrorFormat("Exception: {0}", ex.ToString());
                return false;
            }

            return true;
        }
Esempio n. 6
0
        public void UpdateTest()
        {
            var manager = new ClientManager();
            var client = new Client { Id = Guid.NewGuid(), Name = "Qwest", Projects = new List<Project> { new Project { Id = Guid.NewGuid(), Name = "Connect" } } };
            manager.Create(client);

            client.Projects.Add(new Project { Id = Guid.NewGuid(), Name = "test add" });
            client.Projects.FirstOrDefault().Name = "edited";
            client.Name = "edites";

            bool actual = manager.Update(client);
            Assert.AreEqual(true, actual);
            Assert.AreEqual(client.Name, "edites");
        }