Exemplo n.º 1
0
        public void AddGraph(GraphDto graphDto)
        {
            var graph = graphDtoToGraphMapping.Map(graphDto);

            winContext.Graphs.Add(graph);
            winContext.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult <WorkerDto> Add([FromBody] WorkerDto workerDto)
        {
            if (workerDto.UserName == null)
            {
                return(BadRequest(new { Password = "******" }));
            }

            if (workerDto.Password == null)
            {
                return(BadRequest(new { Password = "******" }));
            }

            Worker worker = workerDtoToWorkerMapping.Map(workerDto);

            User user = new User()
            {
                UserName     = workerDto.UserName,
                Worker       = worker,
                PasswordHash = securityService.HashPassword(workerDto.Password)
            };

            alohaContext.Users.Add(user);
            alohaContext.SaveChanges();

            return(workerToWorkerDtoMapping.Map(worker));
        }
Exemplo n.º 3
0
        public UserDto GetById(int id)
        {
            User user = alohaContext.Users.Find(id);

            return(user == null
                ? null
                : userToUserDtoMapping.Map(user));
        }
Exemplo n.º 4
0
        public OfficeDto Get(int id)
        {
            Office office = dbContext.Offices
                            .Single(o => o.Id == id);

            return(office == null
                ? null
                : officeToOfficeDtoMapping.Map(office));
        }
Exemplo n.º 5
0
        public OfficeDto Add([FromBody] OfficeDto officeDto)
        {
            Office office = officeDtoToOfficeMapping.Map(officeDto);

            dbContext.Set <Office>()
            .Add(office);

            dbContext.SaveChanges();

            return(officeToOfficeDtoMapping.Map(office));
        }
Exemplo n.º 6
0
        public WorkstationDto Get(int floorId, int id)
        {
            Workstation workstation = dbContext.Set <Workstation>()
                                      .Include(w => w.Floor)
                                      .Where(w => w.Floor.Id == floorId)
                                      .SingleOrDefault(w => w.Id == id);

            return(workstation == null
                ? null
                : workstationToWorkstationDtoMapping.Map(workstation));
        }
Exemplo n.º 7
0
        public FloorDto Get(int id)
        {
            Floor floor = dbContext.Set <Floor>()
                          .Include(f => f.Office)
                          .Include(f => f.Workstations)
                          .Include(f => f.Image)
                          .Single(f => f.Id == id);

            return(floor == null
                ? null
                : floorToFloorDtoMapping.Map(floor));
        }
Exemplo n.º 8
0
        public WorkerDto GetById(int id)
        {
            Worker worker = alohaContext.Workers
                            .Include(w => w.User)
                            .Include(w => w.Workstation)
                            .ThenInclude(w => w.Floor)
                            .Include(f => f.Photo)
                            .Single(w => w.Id == id);

            return(worker == null
                ? null
                : workerToWorkerDtoMapping.Map(worker));
        }
Exemplo n.º 9
0
        public WorkstationDto Add(int floorId, [FromBody] WorkstationDto workstationDto)
        {
            Workstation workstation = workstationDtoToWorkstationMapping.Map(workstationDto);

            Floor floor = dbContext.Floors
                          .Include(o => o.Workstations)
                          .SingleOrDefault(o => o.Id == floorId);

            floor.Workstations.Add(workstation);

            dbContext.SaveChanges();

            return(workstationToWorkstationDtoMapping.Map(workstation));
        }
Exemplo n.º 10
0
        public FloorDto Add([FromBody] FloorDto floorDto)
        {
            Floor floor = floorDtoToFloorMapping.Map(floorDto);

            Office office = dbContext.Offices
                            .Include(o => o.Floors)
                            .SingleOrDefault(o => o.Id == floorDto.OfficeId);

            office.Floors.Add(floor);

            dbContext.SaveChanges();

            return(floorToFloorDtoMapping.Map(floor));
        }
Exemplo n.º 11
0
        public void AddConcept(int graphId, ConceptDto conceptDto)
        {
            var graph = winContext.Graphs
                        .SingleOrDefault(g => g.Id == graphId);

            var concept = conceptDtoToConceptMapping.Map(conceptDto);

            concept.Graph = graph;

            foreach (var dependency in winContext.Concepts
                     .Where(c => c.Graph.Id == graphId)
                     .Where(c => conceptDto.DependenciesIds.Contains(c.Id))
                     .ToList())
            {
                concept.Dependencies.Add(dependency);
            }

            winContext.Concepts.Add(concept);
            winContext.SaveChanges();
        }
Exemplo n.º 12
0
        public GraphDto GetGraphById(int id)
        {
            var graph = winContext.Graphs
                        .SingleOrDefault(g => g.Id == id);

            if (graph == null)
            {
                return(null);
            }

            return(graphToGraphDtoMapping.Map(graph));
        }
Exemplo n.º 13
0
        public UserDto Add([FromBody] UserDto userDto)
        {
            User user = userDtoToUserMapping.Map(userDto);

            user.PasswordHash = securityService.HashPassword("test");

            alohaContext.Users.Add(user);

            alohaContext.SaveChanges();

            return(userToUserDtoMapping.Map(user));
        }