public async Task <IActionResult> Edit(int?id, [Bind("IdContainer,numContainer,tipo,tamanho,IdBl")] Models.Container container)
 {
     if (id != container.IdContainer)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             portoContext.Update(container);
             await portoContext.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ContainerExiste(container.IdContainer))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["IdBl"] = new SelectList(portoContext.BLs, "IdBl", "IdBl", container.IdBl);
     return(View(container));
 }
 public void RemoveContainerToContainerGroup(Models.Container c, Models.ContainerGroup cg)
 {
     if (cg.ContainerInGroup.Contains(c))
     {
         cg.ContainerInGroup.Add(c);
     }
 }
 public void Adiciona(Models.Container container)
 {
     using (var context = new Context()) {
         context.Container.Add(container);
         context.SaveChanges();
     }
 }
 public void AddContainer(Models.Container c)
 {
     if (!_store.Containers.Exists(o => o.ResourceId == c.ResourceId))
     {
         _store.Containers.Add(c);
     }
 }
 public void Deletar(Models.Container container)
 {
     using (var contexto = new Context()) {
         contexto.Container.Remove(container);
         contexto.SaveChanges();
     }
 }
 public void Atualiza(Models.Container container)
 {
     using (var contexto = new Context()) {
         contexto.Entry(container).State = System.Data.Entity.EntityState.Modified;
         contexto.SaveChanges();
     }
 }
        public async Task <IActionResult> Create(int id, [Bind("IdContainer,numContainer,tipo,tamanho,IdBl")] Models.Container container)
        {
            if (ModelState.IsValid)
            {
                portoContext.Add(container);
                await portoContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdBl"] = new SelectList(portoContext.BLs, "IdBl", "IdBl");
            return(View(container));
        }
Exemple #8
0
        public virtual IActionResult CreateContainer([FromRoute][Required] string tripId, [FromBody] ContainerCreationDetails containerCreationDetails)
        {
            var trip = GetTripById(tripId);

            if (trip == null)
            {
                return(StatusCode(404));
            }

            // Has the container already been created?
            var container = _repo.Containers.FirstOrDefault(x => x.ContainerId.Equals(containerCreationDetails.Id));

            if (container != null)
            {
                return(StatusCode(400));
            }

            // No, then let's create it
            var model = new Models.Container()
            {
                ContainerId  = containerCreationDetails.Id,
                TripId       = trip.Id,
                ProductCount = containerCreationDetails.ProductCount,

                // Use projection to convert from view model to DTO
                // Note. We don't need to populate ContainerID as EF will take care of referential integrity for us
                Temperatures = containerCreationDetails.Measurements.Select(tr => new Models.TemperatureRecord()
                {
                    Time   = tr.Time,
                    Value  = tr.Value,
                    TripId = trip.Id
                }).ToList()
            };

            model.IsSpoiled      = SpoilageHelpers.IsSpoiled(model.Temperatures, trip.SpoilTemperature, trip.SpoilDuration);
            model.MaxTemperature = model.Temperatures.Max(x => x.Value);

            trip.Updated = DateTime.UtcNow;
            _repo.Containers.Add(model);
            _repo.SaveChanges();
            return(StatusCode(201));
        }
        static void Main(string[] args)
        {
            //SetUp
            Storage  s = new Storage();
            Commands c = new Commands(s);
            Queries  q = new Queries(s);

            var shad = new Models.Person {
                Email = "*****@*****.**", DNVGLID = Guid.NewGuid().ToString(), Id = 1, Name = "Shad"
            };
            var anatoliy = new Models.Person {
                Email = "*****@*****.**", DNVGLID = Guid.NewGuid().ToString(), Id = 2, Name = "Anatoliy"
            };
            var s1 = new Models.Container {
                Id = 1, Name = "ship_01", ResourceId = Guid.NewGuid().ToString()
            };
            var s2 = new Models.Container {
                Id = 2, Name = "ship_02", ResourceId = Guid.NewGuid().ToString()
            };


            c.AddUser(shad);
            c.AddUser(anatoliy);

            c.AddContainer(s1);
            c.AddContainer(s2);

            //Add all ships containers to container grouping ships
            var cg1 = new Models.ContainerGroup {
                Id = 1, name = "ships", ContainerInGroup = new List <Models.Container>()
            };

            c.AddContainerToContainerGroup(s1, cg1);
            c.AddContainerToContainerGroup(s2, cg1);


            //Create user groups to access ships
            var ug1 = new Models.UserGroup {
                Id = 1, name = "readers of ships", PersonInGroup = new List <Models.Person>()
            };
            var ug2 = new Models.UserGroup {
                Id = 2, name = "admin of ships", PersonInGroup = new List <Models.Person>()
            };


            //Add users to a user group
            c.AddPersonToUserGroup(shad, ug1);
            c.AddPersonToUserGroup(shad, ug2);
            c.AddPersonToUserGroup(anatoliy, ug2);

            //Give access to ship
            c.AddContainerGroupToUserGroup(cg1, ug1);
            c.AddContainerGroupToUserGroup(cg1, ug2);

            //Which group has access?
            var o = q.getListOfUserGroupsWithAcessToContainerGroup(cg1);


            Console.WriteLine($"Which group has access to {cg1.name}");
            Console.WriteLine(o.Count);
            foreach (var aa in o)
            {
                Console.WriteLine(aa.name);

                Console.WriteLine("whos in that group?");
                var p = q.getListOfPeapleInGroupQuery(aa);
                foreach (var pp in p)
                {
                    Console.WriteLine(pp.Name);
                }
            }

            Console.WriteLine($"-------------------------");
            Console.WriteLine($"Removing user group {ug1.name} access from container group {cg1.name}");
            //Remove access
            c.RemoveContainerGroupFromUserGroup(cg1, ug1);
            //Which group has access?
            o = q.getListOfUserGroupsWithAcessToContainerGroup(cg1);

            Console.WriteLine($"Which group has access to {cg1.name}");
            Console.WriteLine(o.Count);
            foreach (var aa in o)
            {
                Console.WriteLine(aa.name);

                Console.WriteLine("whos in that group?");
                var p = q.getListOfPeapleInGroupQuery(aa);
                foreach (var pp in p)
                {
                    Console.WriteLine(pp.Name);
                }
            }

            Console.Read();
        }
 public ActionResult Deletar(Models.Container container)
 {
     DAO.ContainerDAO dao = new DAO.ContainerDAO();
     dao.Deletar(container);
     return(RedirectToAction("/viewContainer"));
 }
 public ActionResult Adiciona(Models.Container container)
 {
     DAO.ContainerDAO dao = new DAO.ContainerDAO();
     dao.Adiciona(container);
     return(RedirectToAction("/viewContainer"));
 }