public async Task CreateTypeAsync(string name, double price) { var devicetype = new DeviceType { Id = Guid.NewGuid().ToString(), Type = name, Price = price }; await _context.DeviceTypes.AddAsync(devicetype); await _context.SaveChangesAsync(); }
public async Task <UserDTO> CreateUser(UserDTO user) { var newUser = new User() { FirstName = user.FirstName, LastName = user.LastName, PhoneNumber = user.PhoneNumber, IdentificationNumber = user.IdentificationNumber, RegisteredOn = DateTime.Now, }; await _context.Users.AddAsync(newUser); await _context.SaveChangesAsync(); await _userManager.AddToRoleAsync(newUser, "user"); await _context.SaveChangesAsync(); return(user); }
public async Task <SessionDTO> Create(SessionDTO dto) { var session = new Session() { DeviceID = dto.DeviceID, SessionStart = DateTime.Now, UserID = dto.UserID, }; var user = await _context.Users.FindAsync(dto.UserID); user.IsInSession = true; await _context.SaveChangesAsync(); var device = await _context.Devices.FindAsync(dto.DeviceID); device.Available = false; await _context.SaveChangesAsync(); await _context.Sessions.AddAsync(session); await _context.SaveChangesAsync(); return(dto); }
public async Task <bool> Create(DeviceDTO dto) { if (await _context.Devices.AnyAsync(x => x.DeviceName == dto.DeviceName)) { return(false); } var device = new Device() { DeviceName = dto.DeviceName, Type = dto.Type, Available = true, PlayedTime = new TimeSpan(), }; await _context.Devices.AddAsync(device); await _context.SaveChangesAsync(); return(true); }