Ejemplo n.º 1
0
        public async Task <IActionResult> ModifyRoom(Rooms room)
        {
            try
            {
                List <string> errors = await RoomsHelper.Validations(room, mySQLDBContext, false);

                if (errors.Count != 0)
                {
                    return(BadRequest(errors));
                }

                Rooms inDatabaseRoom = mySQLDBContext.Rooms.FirstOrDefault(x => x.id == room.id && x.idHotel == room.idHotel);

                inDatabaseRoom.roomNumber     = room.roomNumber;
                inDatabaseRoom.maxCapacity    = room.maxCapacity;
                inDatabaseRoom.rate           = room.rate;
                inDatabaseRoom.phoneExtension = room.phoneExtension;

                await mySQLDBContext.SaveChangesAsync();

                return(Ok(inDatabaseRoom));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(500));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddRoom(Rooms room)
        {
            try
            {
                List <string> errors = await RoomsHelper.Validations(room, mySQLDBContext);

                if (errors.Count != 0)
                {
                    return(BadRequest(errors));
                }
                await mySQLDBContext.AddAsync(room);

                await mySQLDBContext.SaveChangesAsync();

                return(Ok(room));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(500));
            }
        }