public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            try
            {
                var entity = await _cateBookingRepository.Query().FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                var resource = new CategoryBooking();
                _mapper.Map(entity, resource);
                response.Model = resource;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Create(CategoryBooking resource)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }

            try
            {
                var area = new CategoryBooking();
                _mapper.Map(resource, area);

                var entity = await _cateBookingRepository.AddAsync(area);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Update(CategoryBookingViewModel model, string saveCommand = null)
        {
            if (!ModelState.IsValid)
            {
                return(View("CategoryBookingForm", model));
            }

            var entity = new CategoryBooking();

            _mapper.Map(model, entity);

            var response = await HttpRequestFactory.Put(Constants.BaseApiUrl + "CategoryBooking/" + model.Id, entity);

            var outmodel = response.ContentAsType <SingleModelResponse <CategoryBooking> >();

            if (outmodel.DidError || !response.IsSuccessStatusCode)
            {
                ViewBag.ErrorMsg = outmodel.ErrorMessage ?? response.ReasonPhrase;
                return(View("CategoryBookingForm", model));
            }
            AlertShow();
            if (saveCommand != Constants.SaveContinute)
            {
                return(RedirectToAction("Index"));
            }

            model = _mapper.Map(outmodel.Model, model);
            return(RedirectToAction("Edit", new { id = model.Id }));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            try
            {
                var entity = await _cateBookingRepository.DeleteAsync(id);

                var resource = new CategoryBooking();
                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Delete;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Update(int id, CategoryBooking resource)
        {
            var response = new SingleModelResponse <CategoryBooking>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }
            try
            {
                var entity = await _cateBookingRepository.FindAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                entity.BookingName = resource.BookingName;
                entity.Position    = resource.Position;
                entity.IsActive    = resource.IsActive;

                await _cateBookingRepository.UpdateAsync(entity);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogInformation(ex.Message);
                _logger.LogTrace(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
Пример #6
0
 public async Task <IActionResult> Create([FromBody] CategoryBooking resource)
 {
     return(await _service.Create(resource));
 }
Пример #7
0
 public async Task <IActionResult> Update(int id, [FromBody] CategoryBooking resource)
 {
     return(await _service.Update(id, resource));
 }