public User CreateUser(UserDTO userDTO)
        {
            byte[] newPassHash, newPassSalt;
            _auth.CreatePasswordHash(userDTO.Password, out newPassHash, out newPassSalt);
            User user = new User
            {
                Name           = userDTO.Name,
                Email          = userDTO.Email,
                IsAdmin        = userDTO.IsAdmin,
                Group          = userDTO.Group,
                ProfilePicture = userDTO.ProfilePicture,
                PasswordHash   = newPassHash,
                PasswordSalt   = newPassSalt,
                PShifts        = userDTO.PShifts,
                Role           = userDTO.Role,
                Shifts         = userDTO.Shifts
            };

            _context.Attach(user).State = EntityState.Added;
            _context.SaveChanges();

            Group group = _context.Groups.FirstOrDefault(g => g.Id == user.Group.Id);

            if (user != null)
            {
                group.Users.Add(user);
                user.Group = group;
            }
            _context.SaveChanges();

            return(user);
        }
 public Route CreateRoute(Route route)
 {
     if (route.Shift != null)
     {
         route.Shift         = _context.Shifts.FirstOrDefault(s => s.Id == route.Shift.Id);
         route.Shift.RouteId = route.Id;
     }
     _context.Attach(route).State = EntityState.Added;
     _context.SaveChanges();
     return(route);
 }
        public PendingShift CreatePendingShift(PendingShift pendingShift)
        {
            pendingShift.ShiftId = pendingShift.Shift.Id;
            _context.Attach(pendingShift).State = EntityState.Added;
            _context.SaveChanges();
            Shift shift = _context.Shifts.FirstOrDefault(s => s.Id == pendingShift.ShiftId);

            shift.PShift = pendingShift;
            _context.Attach(pendingShift).State = EntityState.Modified;
            _context.SaveChanges();
            return(pendingShift);
        }
Esempio n. 4
0
        public Shift CreateShift(Shift shift)
        {
            _context.Attach(shift).State = EntityState.Added;
            _context.SaveChanges();
            Route route = _context.Routes.FirstOrDefault(r => r.Id == shift.Route.Id);

            shift.Route   = route;
            route.Shift   = shift;
            shift.RouteId = route.Id;
            _context.Shifts.Attach(shift).State = EntityState.Modified;
            _context.SaveChanges();
            return(shift);
        }
Esempio n. 5
0
        public Group CreateGroup(Group group)
        {
            _context.Attach(group).State = EntityState.Added;
            _context.SaveChanges();

            /*for (int i = 0; i < group.Users.Count; i++)
             * {
             *  User user = _context.Users.FirstOrDefault(u => u.Id == group.Users[i].Id);
             *  user.Group = group;
             *  group.Users[i] = user;
             *  _context.Groups.Attach(group).State = EntityState.Modified;
             * }
             * _context.SaveChanges();*/
            return(group);
        }