public static ArshidResponse <Object> GetResponse(ModelStateDictionary ModelState, string defaultCode)
        {
            if (ModelState.Keys.First() == "")
            {
                var response = ArshidResponse <Object> .SetResponse(defaultCode + "200", "Invalid Model State.", null);

                return(response);
            }

            var errorKeyFirst = ModelState.Keys.First();

            if (errorKeyFirst == null)
            {
                var response = ArshidResponse <Object> .SetResponse(defaultCode + "200", "Invalid Model State.", null);

                return(response);
            }
            try
            {
                var errorStatus = ModelState[errorKeyFirst].Errors.First().ErrorMessage;
                if (errorStatus == "")
                {
                    errorStatus = "200";                    // fix when parsing failures occur
                }
                var response = ArshidResponse <Object> .SetResponse(defaultCode + errorStatus, errorKeyFirst, null);

                return(response);
            }
            catch (Exception e)
            {
                var response = ArshidResponse <Object> .SetResponse(defaultCode + "200", "Invalid Model State.", null);

                return(response);
            }
        }
示例#2
0
        public async Task <IActionResult> GetGroupLocation(int?userId)
        {
            try
            {
                var result = await _userService.GetGroupLocation(userId.GetValueOrDefault());

                if (!result.Status)
                {
                    var errorResponse = ArshidResponse <Object> .SetResponse("AUC300", result.Message, null);

                    return(new ObjectResult(errorResponse));
                }

                var success = ArshidResponse <Object> .SetResponse("AUC100", result.Message, result.Data);

                return(new ObjectResult(success));
            }
            catch (Exception ex)
            {
                var response = ArshidResponse <Object> .SetResponse("AUC300", ex.Message, null);

                return(new ObjectResult(response));
            }
        }
示例#3
0
        public async Task <IActionResult> GenerateZonalHeatmap()
        {
            try
            {
                var result = await _userService.GenerateZonalHeatmap();

                if (!result.Status)
                {
                    var errorResponse = ArshidResponse <Object> .SetResponse("AUI300", result.Message, null);

                    return(new ObjectResult(errorResponse));
                }

                var success = ArshidResponse <Object> .SetResponse("AUI100", result.Message, result.Data);

                return(new ObjectResult(success));
            }
            catch (Exception ex)
            {
                var response = ArshidResponse <Object> .SetResponse("AUI300", ex.Message, null);

                return(new ObjectResult(response));
            }
        }
示例#4
0
        public async Task <IActionResult> SaveUserLocation([FromBody] UserLocationInsertModel userLocation)
        {
            try
            {
                var result = await _userService.SaveUserLocation(userLocation);

                if (!result.Status)
                {
                    var errorResponse = ArshidResponse <Object> .SetResponse("AUA300", result.Message, null);

                    return(new ObjectResult(errorResponse));
                }

                var success = ArshidResponse <Object> .SetResponse("AUA100", result.Message, result.Data);

                return(new ObjectResult(success));
            }
            catch (Exception ex)
            {
                var response = ArshidResponse <Object> .SetResponse("AUA300", ex.Message, null);

                return(new ObjectResult(response));
            }
        }
示例#5
0
        public async Task <IActionResult> ResetDatabaseUsers()
        {
            try
            {
                var result = await _userService.ResetDatabase();

                if (!result.Status)
                {
                    var errorResponse = ArshidResponse <Object> .SetResponse("AUH300", result.Message, null);

                    return(new ObjectResult(errorResponse));
                }

                var success = ArshidResponse <Object> .SetResponse("AUH100", result.Message, true);

                return(new ObjectResult(success));
            }
            catch (Exception ex)
            {
                var response = ArshidResponse <Object> .SetResponse("AUH300", ex.Message, null);

                return(new ObjectResult(response));
            }
        }