public async Task <IActionResult> Create(CategoryLocalTravel resource)
        {
            var response = new SingleModelResponse <CategoryLocalTravel>();

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

            try
            {
                var entity = new CategoryLocalTravel();
                _mapper.Map(resource, entity);

                var entityAdded = await _repository.AddAsync(entity);

                response.Model   = entityAdded;
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
示例#2
0
        public async Task <IActionResult> Update(CategoryLocalTravelViewModel model, string saveCommand = null)
        {
            await PrepareCityList(model);

            if (!ModelState.IsValid)
            {
                return(View("CategoryLocalTravelForm", model));
            }

            var entity = new CategoryLocalTravel();

            _mapper.Map(model, entity);

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

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

            if (outmodel.DidError || !response.IsSuccessStatusCode)
            {
                ViewBag.ErrorMsg = outmodel.ErrorMessage ?? response.ReasonPhrase;
                return(View("CategoryLocalTravelForm", 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> Update(int id, CategoryLocalTravel resource)
        {
            var response = new SingleModelResponse <CategoryLocalTravel>();

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

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

                entity.LocalName   = resource.LocalName;
                entity.LocalCode   = resource.LocalCode;
                entity.IdCity      = resource.IdCity;
                entity.Description = resource.Description;
                entity.IsActive    = resource.IsActive;

                await _repository.UpdateAsync(entity);

                response.Model   = entity;
                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());
        }
示例#4
0
 public async Task <IActionResult> Create([FromBody] CategoryLocalTravel resource)
 {
     return(await _service.Create(resource));
 }
示例#5
0
 public async Task <IActionResult> Update(int id, [FromBody] CategoryLocalTravel resource)
 {
     return(await _service.Update(id, resource));
 }