Пример #1
0
        public IActionResult Edit(int id)
        {
            BungalowBindingModel model = this.bungalowsService.GetById <BungalowBindingModel>(id);

            this.ViewBag.Id = id;

            return(this.View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, BungalowBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.bungalowsService.UpdateAsync(id, model);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Пример #3
0
        public async Task CreateAsync(BungalowBindingModel model)
        {
            Bungalow bungalow = new Bungalow
            {
                Number      = model.Number,
                Rooms       = model.Rooms,
                Type        = model.Type,
                IsAvailable = model.IsAvailable,
                Notes       = model.Notes,
                Beds        = model.Beds,
            };

            await this.bungalowsRepository.AddAsync(bungalow);

            await this.bungalowsRepository.SaveChangesAsync();
        }
Пример #4
0
        public async Task UpdateAsync(int id, BungalowBindingModel model)
        {
            Bungalow bungalow = this.bungalowsRepository.All()
                                .FirstOrDefault(b => b.Id == id);

            if (bungalow == null)
            {
                throw new ArgumentNullException("There is no bungalow with this id.");
            }

            bungalow.Number      = model.Number;
            bungalow.Rooms       = model.Rooms;
            bungalow.Type        = model.Type;
            bungalow.IsAvailable = model.IsAvailable;
            bungalow.Notes       = model.Notes;
            bungalow.Beds        = model.Beds;

            await this.bungalowsRepository.SaveChangesAsync();
        }