Ejemplo n.º 1
0
 public Room(MNewRoom newRoom, int personId)
 {
     Id               = 0;
     Name             = newRoom.Name;
     Code             = newRoom.Code;
     ExpirationDate   = newRoom.ExpirationDate;
     Description      = newRoom.Description;
     CurrentState     = (int)ERoomState.Building;
     NumberOfStudents = 0;
     PersonId         = personId;
 }
Ejemplo n.º 2
0
        public IActionResult CreateRoom([FromBody] MNewRoom newRoom)
        {
            var errors = new List <MModelError>();

            newRoom.ValidRoom(_uRoom, ref errors);
            if (errors.Any())
            {
                return(BadRequest(ResponseContent.Create(errors, HttpStatusCode.BadRequest, "Campo(s) inválido(s)!")));
            }

            if (newRoom.ExpirationDate != null && newRoom.ExpirationDate < DateTime.Now)
            {
                return(BadRequest(ResponseContent.Create(errors, HttpStatusCode.BadRequest, $"A data do fim da sala deve ser maior que hoje, {DateTime.Now:dd/MM/yyyy}!")));
            }

            var authenticatedUserId = HttpContext.Session.GetSessionPersonId();

            _bRoom.Save(newRoom, authenticatedUserId);

            _bHistory.SaveHistory(authenticatedUserId, "Usuário criou uma nova sala");

            return(Ok(ResponseContent.Create(null, HttpStatusCode.Created, "Sala criada com sucesso!")));
        }