Пример #1
0
        public async Task <IActionResult> GetReplies(int projectId, int pageIndex, int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <PagedListModel <string> > response = new ResponseHttp <PagedListModel <string> >();

            try
            {
                ResponseDto <PagedListModel <string> > res = await participationService.GetParticipationLogsByProjectIdAsync(projectId, platformId, pageIndex, (int)ParticipationStatus.Reply_Comment);

                if (res.StatusCode == Core.Enums.StatusCode.NotFound)
                {
                    return(NotFound());
                }
                else
                {
                    response.Data       = res.Data;
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex, new { projectId, pageIndex, platformId });
                return(StatusCode(500));
            }
        }
Пример #2
0
        public async Task <IActionResult> GetTerms(int compId, int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <IList <TermDto> > response = new ResponseHttp <IList <TermDto> >();

            try
            {
                var terms = await termRepository.GetParentTermsAsync(compId, platformId);

                if (terms == null)
                {
                    return(NotFound());
                }
                else
                {
                    response.Data       = mapper.Map <IList <TermDto> >(terms);
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex);
                return(StatusCode(500));
            }
        }
Пример #3
0
        public async Task <IActionResult> GeFAQs(int compId, int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <IList <FAQDto> > response = new ResponseHttp <IList <FAQDto> >();

            try
            {
                var faqList = await fAQRepository.GetByCompetitionIdAsync(compId, platformId);

                if (faqList != null && faqList.Count > 0)
                {
                    response.Data       = mapper.Map <IList <FAQDto> >(faqList);
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                    return(Ok(response));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex);
                return(StatusCode(500));
            }
        }
Пример #4
0
 private void PrepareInvalidModelErrors(ResponseHttp response)
 {
     response.StatusCode       = System.Net.HttpStatusCode.BadRequest;
     response.ValidationErrors = ModelState.Values.SelectMany(m => m.Errors).Select(e => new ValidationErrorModel()
     {
         ErrorMessage = e.ErrorMessage
     }).ToList();
 }
Пример #5
0
        public ActionResult login([FromBody] LoginRequest request)
        {
            UsuariosDomain usuario = new UsuariosDomain();
            var            data    = usuario.auth(request.usuario, request.password);

            if (data.estado != 0)
            {
                data.usuario.password = "******";
                return(ResponseHttp.ok("Successfully", new { usuario = data.usuario, token = data.token }));
            }
            return(ResponseHttp.NoEncontrado("No se encontraron datos"));
        }
Пример #6
0
        public ActionResult get()
        {
            ProductosDomain productosDomain = new ProductosDomain();
            var             productos       = productosDomain.get();

            if (productos.Count > 0)
            {
                return(ResponseHttp.ok(null, productos));
            }

            return(ResponseHttp.NoEncontrado("No se encontro datos"));
        }
Пример #7
0
        public async Task <ResponseHttp> CreateParticipation(ParticipationApiDto dto)
        {
            ResponseHttp response = new ResponseHttp();

            try
            {
                response = await participationService.Save(dto);
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex, dto);
                response.StatusCode = System.Net.HttpStatusCode.InternalServerError;
            }
            return(response);
        }
Пример #8
0
        public ActionResult crear(crearProductoRequest request)
        {
            ProductosDomain productosDomain = new ProductosDomain();
            Productos       producto        = new Productos()
            {
                codigo   = request.codigo,
                nombre   = request.nombre,
                valor    = request.valor,
                cantidad = request.cantidad
            };

            long codproducto = productosDomain.crear(producto);

            if (codproducto != -1)
            {
                return(ResponseHttp.ok("Successfully"));
            }
            return(ResponseHttp.InternalError("No se pudo registrar el producto, error inesperado"));
        }
Пример #9
0
        public ResponseHttp <IList <CompetitionDto> > GetCompetitions(int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <IList <CompetitionDto> > response = new ResponseHttp <IList <CompetitionDto> >();

            try
            {
                var compResponse = competitionService.ListAsync_Api(platformId);
                if (compResponse.StatusCode == Core.Enums.StatusCode.OK)
                {
                    response.Data       = compResponse.Data;
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex);
            }

            return(response);
        }
Пример #10
0
        public async Task <ResponseHttp <ParticipationPreviewApiDto> > GetParticipationPreview(int id, int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <ParticipationPreviewApiDto> response = new ResponseHttp <ParticipationPreviewApiDto>();

            try
            {
                var res = await participationService.GetParticipationPreviewAsync(id, platformId);

                if (res.StatusCode == Core.Enums.StatusCode.OK)
                {
                    response.Data       = res.Data;
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex);
            }

            return(response);
        }
Пример #11
0
        public async Task <ResponseHttp <CompetitionFieldDto> > CompetitionField(int id, int platformId = (int)Platforms.Hulool)
        {
            ResponseHttp <CompetitionFieldDto> response = new ResponseHttp <CompetitionFieldDto>();

            try
            {
                var compResponse = await competitionService.GetCompetitionFieldAsync(id, platformId);

                if (compResponse.StatusCode == Core.Enums.StatusCode.OK)
                {
                    response.Data       = compResponse.Data;
                    response.StatusCode = System.Net.HttpStatusCode.OK;
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex);
            }

            return(response);
        }
Пример #12
0
        private async Task <ResponseHttp <ApplicationUser> > AuthenticateUser(ClientModel model)
        {
            ResponseHttp <ApplicationUser> response = new ResponseHttp <ApplicationUser>();

            if (ModelState.IsValid)
            {
                var userObj = await userManager.FindByNameAsync(model.UserName);

                if (userObj != null)
                {
                    var result = await signInManager.CheckPasswordSignInAsync(userObj, model.Password, false);

                    if (result.Succeeded)
                    {
                        response.StatusCode = System.Net.HttpStatusCode.OK;
                        response.Data       = userObj;
                    }
                    else
                    {
                        response.StatusCode = System.Net.HttpStatusCode.Unauthorized;
                        response.ValidationErrors.Add(new ValidationErrorModel {
                            ErrorMessage = $"{Resource.UserName} {Resource.Or} {Resource.Password} {Resource.Invalid}", PropertyName = "Password"
                        });
                    }
                }
                else
                {
                    response.StatusCode = System.Net.HttpStatusCode.BadRequest;
                    response.ValidationErrors.Add(new ValidationErrorModel {
                        ErrorMessage = $"{Resource.UserName} {Resource.Invalid}", PropertyName = "UserName"
                    });
                }
            }
            else
            {
                PrepareInvalidModelErrors(response);
            }
            return(response);
        }
Пример #13
0
        public async Task <IActionResult> Login(ClientModel model)
        {
            try
            {
                var response = await AuthenticateUser(model);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    ResponseHttp res = new ResponseHttp();
                    res.StatusCode = System.Net.HttpStatusCode.OK;
                    res.Message    = GenerateToken(response.Data);
                    return(Ok(res));
                }
                else
                {
                    return(Unauthorized(response.ValidationErrors));
                }
            }
            catch (Exception ex)
            {
                commonFunctions.LogError(ex, model);
                return(StatusCode(500));
            }
        }