public IActionResult Create([FromBody] Hotel value)
 {
     return(Ok(new List <Hotel>()
     {
         service.Create(value)
     }));
 }
Esempio n. 2
0
        public IActionResult Create([FromForm] HotelViewModel model)
        {
            if (String.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError(nameof(HotelViewModel.Name), "The Name field is required.");
            }

            if (String.IsNullOrEmpty(model.Description))
            {
                ModelState.AddModelError(nameof(HotelViewModel.Description), "The Description field is required.");
            }

            if (ModelState.IsValid)
            {
                var hotel   = _mapper.Map <HotelViewModel, Hotel>(model);
                var hotelId = Guid.NewGuid();
                hotel.Id = hotelId;

                //if (!String.IsNullOrEmpty(model.Room))
                //{
                //    var room = _roomService.GetRoomByName(model.Room);
                //}

                _hotelService.Create(hotel);

                return(StatusCode(201));
            }

            return(StatusCode(400));
        }
        public ActionResult Create([FromBody] Hotel form)
        {
            var hotelId = service.Create(form).Result;

            if (hotelId > 0)
            {
                return(Ok(new { message = "Creado con Exito" }));
            }

            return(Json(new { message = "Ocurrio un Error" }));
        }
Esempio n. 4
0
        public async Task <ActionResult> Create(Hotel hotel)
        {
            try
            {
                await hotelService.Create(hotel);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 5
0
        public IActionResult CreateHotel([FromBody] HotelCreateModel model)
        {
            // map model to entity
            var hotel         = _mapper.Map <Hotel>(model);
            var currentUserId = int.Parse(User.Identity.Name);

            try
            {
                // create user
                _hotelService.Create(hotel, currentUserId);
                return(Ok($"You have created successfully a hotel. \n Name: {hotel.Name} "));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Esempio n. 6
0
        public IActionResult Add(HotelViewModel entity)
        {
            if (String.IsNullOrEmpty(entity.Name))
            {
                ModelState.AddModelError(nameof(HotelViewModel.Name), "The Name field is required.");
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                ModelState.AddModelError(nameof(HotelViewModel.Description), "The Description field is required.");
            }

            if (ModelState.IsValid)
            {
                var hotel   = _mapper.Map <HotelViewModel, Hotel>(entity);
                var hotelId = Guid.NewGuid();
                hotel.Id = hotelId;

                //if (!String.IsNullOrEmpty(entity.Room))
                //{
                //    var room = _roomService.GetRoomByName(entity.Room);
                //}

                //if (entity.Images.Any())
                //{
                //    AddPictureSync(entity.Images, entity.Key);
                //}

                _hotelService.Create(hotel);

                return(RedirectToAction("Index"));
            }

            //var rooms = _roomService.GetAllRoomCompanyNames().ToList();

            return(View(entity));
        }
        public async Task <ActionResult> CreateHotel([FromBody] Hotel hotel)
        {
            await _hotelService.Create(hotel);

            return(Ok());
        }
 public void PostHotel(Hotel hotel)
 {
     hotelService.Create(hotel);
 }
Esempio n. 9
0
        public void commandReader()
        {
            try
            {
                string   textFile = AppDomain.CurrentDomain.BaseDirectory + "//input.txt";
                string[] lines    = File.ReadAllLines(textFile);
                foreach (string line in lines)
                {
                    var command = line.Split(' ');
                    switch (command[0])
                    {
                    case "create_hotel":
                    {
                        int FloorNumber = int.Parse(command[1]);
                        int RoomAmount  = int.Parse(command[2]);
                        var resp        = hotelService.Create(FloorNumber, RoomAmount);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "book":
                    {
                        string RoomNumber = command[1];
                        string GuestName  = command[2];
                        int    Age        = int.Parse(command[3]);
                        var    resp       = hotelService.Book(RoomNumber, GuestName, Age);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "list_available_rooms":
                    {
                        var resp = hotelService.AvailableRooms();
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "checkout":
                    {
                        int    Keycard   = int.Parse(command[1]);
                        string GuestName = command[2];
                        var    resp      = hotelService.Checkout(Keycard, GuestName);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "list_guest":
                    {
                        var resp = hotelService.Guests();
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "get_guest_in_room":
                    {
                        string RoomNumber = command[1];
                        var    resp       = hotelService.GuestInRoom(RoomNumber);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "list_guest_by_age":
                    {
                        string Operand = command[1];
                        int    Age     = int.Parse(command[2]);
                        var    resp    = hotelService.GuestsByAge(Operand, Age);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "list_guest_by_floor":
                    {
                        int FloorNumber = int.Parse(command[1]);
                        var resp        = hotelService.GuestsByFloor(FloorNumber);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "checkout_guest_by_floor":
                    {
                        int FloorNumber = int.Parse(command[1]);
                        var resp        = hotelService.CheckoutGuestByFloor(FloorNumber);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    case "book_by_floor":
                    {
                        int    FloorNumber = int.Parse(command[1]);
                        string GuestName   = command[2];
                        int    Age         = int.Parse(command[3]);
                        var    resp        = hotelService.BookByFloor(FloorNumber, GuestName, Age);
                        Console.WriteLine(resp.Result);
                        break;
                    }

                    default: break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR!!!!!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }