Exemplo n.º 1
0
        public IActionResult CreateMeetings([FromBody] CreateMeetingDto createMeetingDto)
        {
            if (createMeetingDto.Quantity == "one")
            {
                var meeting = _mapper.Map <Meetings>(createMeetingDto);
                _context.Meetings.Add(meeting);
                _context.SaveChanges();
            }
            else if (createMeetingDto.Quantity == "all")
            {
                var offices = _context.Offices;

                foreach (Offices o in offices)
                {
                    var meeting = _mapper.Map <Meetings>(createMeetingDto);
                    meeting.OfficeId = Convert.ToInt32(o.Id);
                    _context.Meetings.Add(meeting);
                }
                _context.SaveChanges();
            }
            else
            {
                throw new AppException("Offices quantity is required");
            }
            return(Ok());
        }
Exemplo n.º 2
0
        public Users Create(Users user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Email == user.Email))
            {
                throw new AppException("Username \"" + user.Email + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.Password     = "";
            user.CreatedAt    = DateTime.Now;
            user.UpdatedAt    = DateTime.Now;

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

            return(user);
        }