public ActionResult Create(RoomInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var room = this.Mapper.Map<Room>(model);
            this.rooms.CreateRoom(room);

            this.TempData["Success"] = "Room was successful added!";
            return this.RedirectToAction("Index");
        }
        public ActionResult Create(RoomInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var room = this.Mapper.Map <Room>(model);

            this.rooms.CreateRoom(room);

            this.TempData["Success"] = "Room was successful added!";
            return(this.RedirectToAction("Index"));
        }
Exemple #3
0
        public async Task <IActionResult> Create(RoomInputModel createModel)
        {
            if (!await roomService.IsRoomNumberFree(createModel.Number))
            {
                ModelState.AddModelError(nameof(createModel.Number), "Room with this number alreay exists");
            }

            if (createModel.UseSamePhoto)
            {
                ModelState.AddModelError("Error", "Error parsing your request");
            }
            else if (createModel.PhotoUpload != null)
            {
                var timestamp = $"{DateTime.Today.Day}-{DateTime.Today.Month}-{DateTime.Today.Year}";
                var fileName  = $"_{timestamp}_HMS_RoomPhoto";

                IFormFile file = createModel.PhotoUpload;

                using var stream = new MemoryStream();
                await file.CopyToAsync(stream);

                var photoUrl = await imageManager.UploadImageAsync(stream, fileName);

                if (string.IsNullOrWhiteSpace(photoUrl) || photoUrl.StartsWith("Error"))
                {
                    ModelState.AddModelError(nameof(createModel.PhotoUpload), $"An error occured: {photoUrl}.");
                    return(this.View(createModel));
                }

                var room = new Room
                {
                    Capacity      = createModel.Capacity,
                    AdultPrice    = createModel.AdultPrice,
                    ChildrenPrice = createModel.ChildrenPrice,
                    Type          = createModel.Type,
                    Number        = createModel.Number,
                    ImageUrl      = photoUrl,
                };

                await roomService.AddRoom(room);

                return(RedirectToAction(nameof(Index)));
            }

            ModelState.AddModelError(nameof(createModel.PhotoUpload), "Image is required. Upload one.");
            return(this.View(createModel));
        }
Exemple #4
0
        public IActionResult CreateRoom(RoomInputModel model)
        {
            if (ModelState.IsValid)
            {
                if ((model.MaxNumOfAdults <= 0 && model.MaxNumOfChildren <= 0) || model.MaxNumOfAdults < 0 || model.MaxNumOfChildren < 0)
                {
                    HttpContext.Session.SetString("Message", "Please check Room capacity for Adults and Children.");
                    return(RedirectToAction(nameof(CreateRoom)));
                }

                var room = Room.New(model.RoomType, model.MaxNumOfAdults, model.MaxNumOfChildren);

                _roomRepository.AddRoom(room);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
        public ActionResult Rooms_Create([DataSourceRequest]DataSourceRequest request, RoomInputModel room)
        {
            var newId = 0;
            if (ModelState.IsValid)
            {
                var entity = new Room
                {
                    Name = room.Name,
                    Capacity = room.Capacity
                };

                entity.CreatedOn = DateTime.Now;
                this.rooms.Add(entity);
                this.rooms.SaveChanges();
                newId = entity.Id;
            }

            var roomToDisplay = this.rooms.All().Project()
                .To<RoomViewModel>()
                .FirstOrDefault(x => x.Id == newId);
            return Json(new[] { roomToDisplay }.ToDataSourceResult(request, ModelState));
        }
Exemple #6
0
 public Task <int> Create(RoomInputModel model)
 {
     throw new NotImplementedException();
 }
Exemple #7
0
 public IActionResult Create(RoomInputModel model)
 {
     return(this.View());
 }
Exemple #8
0
        public async Task <IActionResult> Update(string id, RoomInputModel input)
        {
            var uRoom = await roomService.GetRoom <RoomInputModel>(id);

            if (uRoom == null)
            {
                return(this.NotFound());
            }

            if (!await roomService.IsRoomNumberFree(input.Number, id))
            {
                ModelState.AddModelError(nameof(input.Number), "Number with same Id already exists");
            }

            if (!ModelState.IsValid)
            {
                return(this.View(input));
            }

            string photoUrl = string.Empty;

            if (input.UseSamePhoto)
            {
                photoUrl = (await roomService.GetRoom <RoomViewModel>(id)).ImageUrl;
            }
            else if (input.PhotoUpload != null)
            {
                var timestamp = $"{DateTime.Today.Day}-{DateTime.Today.Month}-{DateTime.Today.Year}";
                var fileName  = $"_{timestamp}_HMS_RoomPhoto";

                IFormFile file = input.PhotoUpload;

                using var stream = new MemoryStream();
                await file.CopyToAsync(stream);

                photoUrl = await imageManager.UploadImageAsync(stream, fileName);

                if (string.IsNullOrWhiteSpace(photoUrl) || photoUrl.StartsWith("Error"))
                {
                    ModelState.AddModelError(nameof(input.PhotoUpload), $"An error occured: {photoUrl}.");
                    return(this.View(input));
                }
            }
            else
            {
                return(this.View(input));
            }

            var room = new Room
            {
                Capacity      = input.Capacity,
                AdultPrice    = input.AdultPrice,
                ChildrenPrice = input.ChildrenPrice,
                Type          = input.Type,
                Number        = input.Number,
                ImageUrl      = photoUrl,
            };

            await roomService.UpdateRoom(id, room);

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult Rooms_Create([DataSourceRequest] DataSourceRequest request, RoomInputModel room)
        {
            var newId = 0;

            if (ModelState.IsValid)
            {
                var entity = new Room
                {
                    Name     = room.Name,
                    Capacity = room.Capacity
                };

                entity.CreatedOn = DateTime.Now;
                this.rooms.Add(entity);
                this.rooms.SaveChanges();
                newId = entity.Id;
            }

            var roomToDisplay = this.rooms.All().Project()
                                .To <RoomViewModel>()
                                .FirstOrDefault(x => x.Id == newId);

            return(Json(new[] { roomToDisplay }.ToDataSourceResult(request, ModelState)));
        }