Esempio n. 1
0
        public virtual async Task <IActionResult> Delete([FromBody] RequestDTO request)
        {
            try
            {
                var data = await _service.FindByIdAsync(request.Id);

                if (data == null)
                {
                    return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                         (int)HttpStatusCode.NotAcceptable, _globalLocalizer["ItemNotFoundMessage"])));
                }

                await _service.DeleteAsync(request.Id, Token);

                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.OK, _globalLocalizer["DeleteSuccessMessage"])));
            }
            catch (ValidationServiceException ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.NotAcceptable, ex.ToUlHtmlString())));
            }
            catch (ApplicationException ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.ToUlHtmlString())));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
        public async Task <IActionResult> Post([FromForm]
                                               VehicleDTO vehicleDTO)
        {
            try
            {
                vehicleDTO.UserAdd  = this.User.ToString();
                vehicleDTO.UserEdit = this.User.ToString();

                if (vehicleDTO.File == null || vehicleDTO.File.Length == 0)
                {
                    return(Content("file not selected"));
                }

                return(Json(this.vehicleService.CreateVehicle(vehicleDTO).AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (ApplicationException ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.Message)));
            }
            catch (Exception ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.StackTrace)));
            }
        }
Esempio n. 3
0
        public virtual async Task <IActionResult> Create([FromBody] TDTO modelDTO)
        {
            try
            {
                var data = await ServiceCreate(modelDTO, Token);

                return(Json(data.AsResponseDTO((int)HttpStatusCode.OK,
                                               _globalLocalizer["CreateSuccessMessage"])));
            }
            catch (ValidationServiceException ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.NotAcceptable, ex.ToUlHtmlString())));
            }
            catch (ApplicationException ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.ToUlHtmlString())));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
        public async Task<IActionResult> CreateAsync([FromBody]UserRegisterDTO user)
        {
            try
            {

                var data = await userService.CrearUsuario(user);
                return Json(data.AsResponseDTO((int)HttpStatusCode.OK));
            }
            catch (ApplicationException ex)
            {
                return Json(ResponseExtension.AsResponseDTO<string>(null,
                    (int)HttpStatusCode.InternalServerError, ex.Message));
            }
            catch (ValidationServiceException ex)
            {
                return Json(ResponseExtension.AsResponseDTO<string>(null,
                    (int)HttpStatusCode.NotAcceptable, ex.Message));
            }
            catch (Exception ex)
            {
                return Json(ResponseExtension.AsResponseDTO<string>(null,
                    (int)HttpStatusCode.InternalServerError, ex.Message));
            }

        }
Esempio n. 5
0
        public virtual async Task <IActionResult> Index([FromBody] PagingParams pagingParams)
        {
            try
            {
                var data = await _service.GetAllPagedAsync(pagingParams, Token);

                return(Json(data.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
Esempio n. 6
0
        public virtual async Task <IActionResult> Index()
        {
            try
            {
                var data = await _service.GetAllAsync(Token);

                return(Json(data.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.Message.ToString())));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> MoveDetails(int id)
        {
            try
            {
                var listMoveDetail = this.moveDetailService.GetMovingGrips(id);

                var listToDownload = this.moveService.GetMovingGrips(listMoveDetail);

                return(Json(listToDownload.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
Esempio n. 8
0
        public virtual async Task <IActionResult> Edit([FromBody] TDTO modelDTO)
        {
            try
            {
                int?id = (int?)modelDTO.GetPrimaryKeyValue();
                if (!id.HasValue)
                {
                    return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                         (int)HttpStatusCode.NotAcceptable, _globalLocalizer["ItemNotFoundMessage"])));
                }

                var data = await _service.FindByIdAsync(id, Token);

                if (data == null)
                {
                    return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                         (int)HttpStatusCode.NotAcceptable, _globalLocalizer["ItemNotFoundMessage"])));
                }

                var result = await ServiceUpdate(modelDTO, Token);

                return(Json(result.AsResponseDTO((int)HttpStatusCode.OK,
                                                 _globalLocalizer["UpdateSuccessMessage"])));
            }
            catch (ValidationServiceException ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.NotAcceptable, ex.ToUlHtmlString())));
            }
            catch (ApplicationException ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["UpdateErrorMessage"])));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
        public async Task <IActionResult> Post([FromForm]  FileDTO file)
        {
            try
            {
                if (file.File == null || file.File.Length == 0)
                {
                    return(Json(string.Empty.AsResponseDTO((int)HttpStatusCode.NoContent)));
                }

                var listToDownload = await this.moveService.CreateMove(file);

                return(Json(listToDownload.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> UploadFiles([FromForm]  MoveFileDTO file)
        {
            try
            {
                if (file.File == null || file.File.Length == 0)
                {
                    return(Json(_configuration.GetConnectionString("EmptyFile").AsResponseDTO((int)HttpStatusCode.NoContent)));
                }

                var listToDownload = await this.moveService.CreateMove(file);

                return(Json(listToDownload.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.Message)));
            }
        }
Esempio n. 11
0
        public virtual async Task <IActionResult> Details(int id)
        {
            try
            {
                var data = await _service.FindByIdAsync(id, Token);

                if (data == null)
                {
                    return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                         (int)HttpStatusCode.NotAcceptable, _globalLocalizer["ItemNotFoundMessage"])));
                }
                return(Json(data.AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, _globalLocalizer["DefaultError"])));
            }
        }
        public async Task <IActionResult> UploadFile([FromForm]
                                                     IFormFile file)
        {
            try
            {
                if (file == null || file.Length == 0)
                {
                    return(Content("file not selected"));
                }

                return(Json(this.vehicleService.CreateFileVehicle(file, this.User.ToString()).AsResponseDTO((int)HttpStatusCode.OK)));
            }
            catch (ApplicationException ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.Message)));
            }
            catch (Exception ex)
            {
                return(Json(ResponseExtension.AsResponseDTO <string>(null,
                                                                     (int)HttpStatusCode.InternalServerError, ex.StackTrace)));
            }
        }
 public virtual async Task<IActionResult> Login([FromBody]UserDTO user)
 {
     try
     {
         var data = await this.userService.Login(user);
         return Json(data.AsResponseDTO((int)HttpStatusCode.OK));
     }
     catch (ApplicationException ex)
     {
         return Json(ResponseExtension.AsResponseDTO<string>(null,
             (int)HttpStatusCode.InternalServerError, ex.Message));
     }
     catch (ValidationServiceException ex)
     {
         return Json(ResponseExtension.AsResponseDTO<string>(null,
             (int)HttpStatusCode.NotAcceptable, ex.Message));
     }
     catch (Exception ex)
     {
         return Json(ResponseExtension.AsResponseDTO<string>(null,
             (int)HttpStatusCode.InternalServerError, ex.StackTrace));
     }
 }