Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(Guid id, BookingViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = getOperation.Exception.Message
                    }));
                }
                if (getOperation.Result == null)
                {
                    return(NotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        return(View("Error", new ErrorViewModel()
                        {
                            RequestId = updateOperation.Exception.Message
                        }));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update([FromBody] BookingViewModel vm)
        {
            var getResult = await _bo.ReadAsync(vm.Id);

            if (!getResult.Success)
            {
                return(InternalServerError(getResult.Exception));
            }
            var item = getResult.Result;

            if (item == null)
            {
                return(NotFound());
            }
            if (vm.CompareToModel(item))
            {
                return(NotModified());
            }
            item = vm.ToModel(item);
            var updateResult = await _bo.UpdateAsync(item);

            if (!updateResult.Success)
            {
                return(InternalServerError(updateResult.Exception));
            }
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateAsync([FromBody] BookingViewModel vm)
        {
            var newItem = vm.ToModel();
            var result  = await _bo.CreateAsync(newItem);

            if (!result.Success)
            {
                return(InternalServerError(result.Exception));
            }
            return(Created(Request.Path.Value, null));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(BookingViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = createOperation.Exception.Message
                    }));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }