Ejemplo n.º 1
0
        public IActionResult GetCuisinesV2(ResourceParameter parameters)
        {
            var response = new ListModelResponse <MainMenuDto>() as IListModelResponse <MainMenuDto>;

            //throw new InvalidOperationException("This is an unhandled exception");
            //throw new ECafeException("error occured");

            if (!_propertyMappingService.ValidMappingExistsFor <MainMenuDto, MainMenu>(parameters.OrderBy))
            {
                logger.LogError($"Invalid mapping requested in {this.GetType().Name} Method Name");
                return(response.ToErrorResponse("Invalid mapping requested", HttpStatusCode.BadRequest));
            }

            if (!typeHelperService.TypeHasProperties <MainMenuDto>(parameters.Fields))
            {
                return(response.ToErrorResponse("Invalid properties name requested", HttpStatusCode.BadRequest));
            }

            var results = _mainMenuGetService.GetAll(parameters);

            //***Create pagination header
            var paginationMetadata = ResourceUri <MainMenu> .CreatePaginationHeader(parameters, results, urlHelper, "GetCuisines");

            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

            //***Mapping Entity to Dto
            var medicineTypes = AutoMapper.Mapper.Map <IEnumerable <MainMenuDto> >(results);

            response.ShapeModel = medicineTypes.ShapeData(parameters.Fields);
            response.Model      = new List <MainMenuDto>();
            response.Message    = $"Total of records: {response.ShapeModel.Count()}";
            response.PageSize   = parameters.PageSize;
            response.PageNumber = parameters.PageNumber;
            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetPurchaseOrderStatusesAsync(Int32?pageSize = 10, Int32?pageNumber = 1, String name = null)
        {
            var response = new ListModelResponse <PurchaseOrderStatusViewModel>() as IListModelResponse <PurchaseOrderStatusViewModel>;

            try
            {
                response.PageSize   = (Int32)pageSize;
                response.PageNumber = (Int32)pageNumber;

                response.Model = await Task.Run(() =>
                {
                    return(_RESTfulAPI_Repository
                           .GetPurchaseOrderStatuses(response.PageSize, response.PageNumber, name)
                           .Select(item => item.ToViewModel())
                           .ToList());
                });

                response.Info = String.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 3
0
        public async Task <string> UpdateUserAsync([FromBody] UserViewModel request, int userId)
        {
            //HttpRequest res = null;
            var response       = new ListModelResponse <UserViewModel>();
            var usersDataModel = false;

            try
            {
                usersDataModel = await _userRepository.UpdateUser(request.ToEntity(), userId);

                if (usersDataModel)
                {
                    //  response.Message = String.Format("Record Updated Successfully");
                    response.Message = Messages.SuccessMsg;
                }

                else
                {
                    //  response.Message = String.Format("Record Updation failed");
                    response.Message = Messages.FailMsg;
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 4
0
        public IActionResult GetAll(int?pageSize, int?pageNumber, string q = null)
        {
            var response = new ListModelResponse <AreaResource>
            {
                PageSize   = (int)pageSize,
                PageNumber = (int)pageNumber
            };
            var query = _areaRepository.Query().Include(x => x.Functions)
                        .Skip((response.PageNumber - 1) * response.PageSize)
                        .Take(response.PageSize).ToList();

            if (!string.IsNullOrEmpty(q) && query.Any())
            {
                q     = q.ToLower();
                query = query.Where(x => x.AreaName.ToLower().Contains(q.ToLower()) ||
                                    x.CodeArea.ToLower().Contains(q.ToLower())).ToList();
            }

            try
            {
                response.Model = _mapper.Map(query, response.Model);

                response.Message = string.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 5
0
        public async Task <string> CreateObjectAsync([FromBody] ObjectViewModel request)
        {
            // HttpRequest res = null;
            var response         = new ListModelResponse <ObjectViewModel>();
            var objectsDataModel = 0;

            try
            {
                objectsDataModel = await _objectRepository.CreateObject(request.ToEntity());

                if (objectsDataModel > 0)
                {
                    response.Message = Messages.SuccessMsg;
                }
                //response.Message = String.Format("Created Project Successfully");

                else
                {
                    //  response.Message = String.Format("Create Project failed");
                    response.Message = Messages.FailMsg;
                }
            }

            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> GetUserClubs([FromQuery] string userId)
        {
            var response = new ListModelResponse <Club>()
                           as IListModelResponse <Club>;

            try
            {
                if (userId == null)
                {
                    throw new Exception("User Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    IEnumerable <Club> clubs = _context.GetUserClubs(userId);
                    if (clubs == null)
                    {
                        throw new System.ArgumentNullException("Clubs do not does not Exist");
                    }
                    return(clubs);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 7
0
        public IActionResult DeleteUser(int id, int userId)
        {
            var response = new ListModelResponse <UserListVM>() as IListModelResponse <UserListVM>;

            try
            {
                var data = _userService.GetUserById(id);
                if (data == null)
                {
                    response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    response.Message    = "Something went wrong when deleting data.";
                    response.Success    = "N";
                }
                else
                {
                    data.nactive = 0;
                    _userService.Update(data);
                    _userService.Commit();

                    response.Message    = "Data successfully deleted.";
                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Success    = "Y";
                    response.Data       = _userService.GetAllUserLists();
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                response.Message    = ex.Message;
                response.Success    = "N";
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 8
0
        public async Task <string> CreateProjKeyValueAsync([FromBody] ProjKeyValueViewModel request)
        {
            // HttpRequest res = null;
            var response = new ListModelResponse <ProjKeyValueViewModel>();
            var projkeyvalueDataModel = false;

            try
            {
                projkeyvalueDataModel = await _projkeyvalueRepository.CreateKeyValuePair(request.ToEntity());

                if (projkeyvalueDataModel)
                {
                    // response.Message = String.Format("Created User Successfully");
                    response.Message = Messages.SuccessMsg;
                }
                else
                {
                    //response.Message = String.Format("Create User failed");
                    response.Message = Messages.FailMsg;
                }
            }

            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
        public IActionResult GetAll(int page, string keyword, int pageSize = 3)
        {
            var model    = _productCategoryService.GetAll(keyword);
            int totalRow = model.Count();

            var query        = model.OrderBy(x => x.ID).Skip(page * pageSize).Take(pageSize);
            var responseData = Mapper.Map <IEnumerable <ProductCategoryViewModel> >(query);

            var response = new ListModelResponse <ProductCategoryViewModel>() as IListModelResponse <ProductCategoryViewModel>;

            try
            {
                response.TotalRows = totalRow;
                //rows per page
                response.PageSize   = query.Count();
                response.PageNumber = page;
                response.TotalPages = (int)Math.Ceiling((double)totalRow / pageSize);
                response.Model      = responseData;

                response.Message = String.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 10
0
        public async Task <string> UpdateProjectAsync([FromBody] ProjKeyValueViewModel request, int varId)
        {
            var response          = new ListModelResponse <ProjKeyValueViewModel>();
            var projectsDataModel = false;


            try
            {
                projectsDataModel = await _projkeyvalueRepository.UpdateProjKeyValuePair(request.ToEntity(), varId);

                if (projectsDataModel)
                {
                    response.Message = Messages.SuccessMsg;
                }
                else
                {
                    response.Message = Messages.FailMsg;
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 11
0
        public async Task <string> DeleteProjectAsync(int varId)
        {
            var response = new ListModelResponse <ProjKeyValueViewModel>();

            var projKeyValueDataModel = false;

            try
            {
                projKeyValueDataModel = await _projkeyvalueRepository.DeleteProjKeyValuePair(varId);

                if (projKeyValueDataModel)
                {
                    // response.Message = String.Format("Record Deleted Successfully");
                    response.Message = Messages.SuccessMsg;
                }
                else
                {
                    //response.Message = String.Format("Record Deletion failed");
                    response.Message = Messages.FailMsg;
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> GetCategories()
        {
            var response = new ListModelResponse <CategoryModel>() as IListModelResponse <CategoryModel>;

            var query = await _categoryService.GetCategoriesAsync();

            if (query == null || !query.Any())
            {
                _logger.Warning(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.LIST_ITEMS_NOTFOUND, "LIST_ITEMS_NOTFOUND", RequestPath());

                response.HasError     = true;
                response.ErrorMessage = "LIST_ITEMS_NOTFOUND";
                response.ErrorCode    = LoggingEvents.LIST_ITEMS_NOTFOUND;
                return(response.ToHttpResponse());
            }

            var result = query.Select(x => new CategoryModel()
            {
                Id   = x.Id,
                Name = x.Name
            });

            response.Model   = result;
            response.Message = string.Format("Total of records: {0}", response.Model.Count());

            _logger.Information(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.LIST_ITEMS, "LIST_ITEMS", RequestPath());
            return(response.ToHttpResponse());
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> GetClubEvents([FromQuery] int clubId)
        {
            var response = new ListModelResponse <Event>()
                           as IListModelResponse <Event>;

            try
            {
                if (clubId <= 0)
                {
                    throw new Exception("Club Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    IEnumerable <Event> evnts = _context.GetClubEvents(clubId);;
                    if (evnts == null)
                    {
                        throw new Exception("No Events");
                    }
                    return(evnts);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> GetEventByRoute([FromQuery] int routeId)
        {
            var response = new ListModelResponse <Event>()
                           as IListModelResponse <Event>;

            try
            {
                if (routeId < 1)
                {
                    throw new Exception("User Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    IEnumerable <Event> evnt = _context.GetEventByRoute(routeId);
                    if (evnt == null)
                    {
                        throw new Exception("Event does not Exist");
                    }
                    return(evnt);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetProducts(int?pageSize = 10, int?pageNumber = 1, string name = null)
        {
            var response = new ListModelResponse <ProductViewModel>() as IListModelResponse <ProductViewModel>;

            try
            {
                response.PageSize   = (int)pageSize;
                response.PageNumber = (int)pageNumber;

                response.Model = await Task.Run(() =>
                {
                    var data = ProductRepository
                               .GetProducts(response.PageSize, response.PageNumber, name).ToList();
                    return(ProductRepository
                           .GetProducts(response.PageSize, response.PageNumber, name)
                           .Select(item => item.ToViewModel())
                           .ToList());
                });

                response.Message = string.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Get([FromBody] Search search)
        {
            //TODO: Handle error in the middleware and add try catch there
            IListModelResponse <Employee> response = new ListModelResponse <Employee>();

            try
            {
                _logger.LogInformation(entities.LoggingEvents.ListItems, "respository: {0}", _employeeRepository);

                if (search.TotalCount == 0)
                {
                    response.TotalCount = _employeeRepository.TotalEmployeeCount();
                    _logger.LogInformation(20001, null, "nitin is result:{0}", response.TotalCount);
                }
                List <Employee> employees = await _employeeRepository.GetEmployees(search);

                response.Model   = employees;
                response.Message = "Listed employees successfully";
            }
            catch (Exception ex)
            {
                _logger.LogInformation(entities.LoggingEvents.ListItems, "Exception:{0}", ex);

                response.IsError      = true;
                response.ErrorMessage = "Some Error occured, Please contact to Administrator";
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> GetClubMembers([FromQuery] int clubId)
        {
            var response = new ListModelResponse <ClubMember>()
                           as IListModelResponse <ClubMember>;

            try
            {
                if (clubId < 1)
                {
                    throw new Exception("Club Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    IEnumerable <ClubMember> member = _context.GetMembers(clubId);
                    if (member == null)
                    {
                        throw new Exception("Club Member does not Exist");
                    }
                    return(member);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 18
0
        public async Task <IHttpActionResult> GetAssigned(int id = 0, int page = 0, String namefilter = "",
                                                          String serverNamefilter = "", String versionFilter = "", String sqlversions = "")
        {
            InstanceRepository repository = new InstanceRepository(new MsSqlMonitorEntities());
            IListModelResponse <InstanceViewModel> response = new ListModelResponse <InstanceViewModel>();

            try
            {
                PaginatedInstances data = await repository.GetAssignedInstancesAsync(id, page, namefilter, serverNamefilter, versionFilter, sqlversions);

                response.Model = data.List.Select(i => i.ToViewModel());

                response.PagesCount = data.PageCount;
                response.PageNumber = data.Page;
                response.PageSize   = data.PageSize;
                response.Versions   = data.Versions;
            }
            catch (Exception e)
            {
                response.DidError     = true;
                response.ErrorMessage = e.Message;
            }

            return(response.ToHttpResponse(Request));
        }
Ejemplo n.º 19
0
 public IActionResult Clubs()
 {
     if (ModelState.IsValid)
     {
         ListModelResponse <Club> clubResponse = _context.GetUserClubs(_userManager.GetUserId(User));
         if (clubResponse.DidError == true || clubResponse == null)
         {
             if (clubResponse == null)
             {
                 return(View("Error"));
             }
             Error er = new Error(clubResponse.ErrorMessage);
             return(View("Error", er));
         }
         if (clubResponse.Model != null)
         {
             ViewBag.ClubsByTitle    = clubResponse.Model.OrderBy(p => p.Name);
             ViewBag.ClubsByLocation = clubResponse.Model.OrderBy(p => p.Location);
         }
         string sourceCookie = HttpContext.Request.Cookies["SourcePageClub"];
         if (sourceCookie != null)
         {
             ViewBag.SourcePageClub = sourceCookie;
         }
         return(View(clubResponse.Model));
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 20
0
        public IActionResult GetProducts()
        {
            var pagination = Request.Headers["Pagination"];

            if (!string.IsNullOrEmpty(pagination))
            {
                string[] vals = pagination.ToString().Split(',');
                int.TryParse(vals[0], out page);
                int.TryParse(vals[1], out pageSize);
            }

            int currentPage     = page;
            int currentPageSize = pageSize;
            var totalProducts   = _productRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalProducts / pageSize);


            IEnumerable <Product> _products = _productRepository
                                              .AllIncluding(s => s.Company, s => s.Category, s => s.Brand)
                                              .OrderBy(s => s.Id)
                                              .Skip((currentPage - 1) * currentPageSize)
                                              .Take(currentPageSize)
                                              .ToList();

            Response.AddPagination(page, pageSize, totalProducts, totalPages);

            var response = new ListModelResponse <ProductViewModel>() as IListModelResponse <ProductViewModel>;

            IEnumerable <ProductViewModel> _productsVM = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(_products);

            return(new OkObjectResult(_productsVM));
        }
Ejemplo n.º 21
0
        public IActionResult Get()
        {
            int pageNumber = 1; int pageSize = 10;
            var response = new ListModelResponse <UserType>() as IListModelResponse <UserType>;

            try
            {
                if (ModelState.IsValid)
                {
                    var data             = _userType.GetAllUserTypes();
                    int skip             = (pageNumber - 1) * pageSize;
                    int totalRecordCount = data.Count();
                    int pageCount        = totalRecordCount > 0 ? (int)Math.Ceiling(totalRecordCount / (double)pageSize) : 0;

                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Count      = data.Count();
                    response.Success    = "Y";
                    response.PageNumber = pageNumber;
                    response.PageSize   = pageSize;
                    response.Data       = data.ToList();
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                response.Message    = ex.Message;
                response.Count      = 0;
                response.Success    = "N";
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 22
0
        public async Task <string> UpdateScenarioAsync([FromBody] ScenarioViewModel request, int projectId)
        {
            var response           = new ListModelResponse <ScenarioViewModel>();
            var scenariosDataModel = false;


            try
            {
                scenariosDataModel = await _scenarioRepository.UpdateScenario(request.ToEntity(), projectId);

                if (scenariosDataModel)
                {
                    //   response.Message = String.Format("Record Updated Successfully");
                    response.Message = Messages.SuccessMsg;
                }
                else
                {
                    //  response.Message = String.Format("Record Updation failed");
                    response.Message = Messages.FailMsg;
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 23
0
        public IActionResult GetAll(int?pageSize, int?pageNumber, string q = null)
        {
            var response = new ListModelResponse <CategoryBooking>
            {
                PageSize   = (int)pageSize,
                PageNumber = (int)pageNumber
            };
            var query = _cateBookingRepository.Query().Skip((response.PageNumber - 1) * response.PageSize)
                        .Take(response.PageSize).ToList();

            if (!string.IsNullOrEmpty(q) && query.Any())
            {
                q     = q.ToLower();
                query = query.Where(x => x.BookingName.ToLower().Contains(q.ToLower())).ToList();
            }

            try
            {
                response.Model = _mapper.Map(query, response.Model);

                response.Message = string.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 24
0
        public async Task <string> DeleteScenAsync([FromBody] ScenarioViewModel request)
        {
            var response = new ListModelResponse <ScenarioViewModel>();

            var scenariosDataModel = false;

            try
            {
                scenariosDataModel = await _scenarioRepository.DeleteScenario(request.ToEntity());

                if (scenariosDataModel)
                {
                    response.Message = Messages.DeletionSuccessMsg;
                }
                else
                {
                    response.Message = Messages.DeletionFailMsg;
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> GetUserRoutes([FromQuery] string userId)
        {
            var response = new ListModelResponse <Route>()
                           as IListModelResponse <Route>;

            try
            {
                if (userId == null)
                {
                    throw new Exception("User Id is null");
                }
                response.Model = await Task.Run(() =>
                {
                    IEnumerable <Route> routes = _context.GetUserRoutes(userId);
                    if (routes == null)
                    {
                        throw new Exception("There are no routes");
                    }
                    return(routes);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }
Ejemplo n.º 26
0
        public async Task <string> CreateScenarioAsync([FromBody] ScenarioViewModel request)
        {
            // HttpRequest res = null;
            var response          = new ListModelResponse <ScenarioViewModel>();
            var scenarioDataModel = 0;

            try
            {
                //Logic to add new scenario comes here
                var maxscenId = await _scenarioRepository.GetMaxScenarioId(request.ProjectId.Value);

                request.MainScenarioId = Convert.ToString(Convert.ToInt32(maxscenId.FirstOrDefault()) + 1); //ends here
                scenarioDataModel      = await _scenarioRepository.CreateScenario(request.ToEntity());


                if (scenarioDataModel > 0)
                {
                    // response.Message = String.Format("Created User Successfully");
                    response.Message = Messages.CreateSuccessMsg;
                }
                else
                {
                    //response.Message = String.Format("Create User failed");
                    response.Message = Messages.CreateFailMsg;
                }
            }

            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> GetUsersAsync()
        {
            var response = new ListModelResponse <UserViewModel>();

            try
            {
                // response.PageSize = (Int32)pageSize;
                // response.PageNumber = (Int32)pageNumber;

                var usersDataModel = await _userRepository
                                     .GetUsers();

                response.Model = usersDataModel.Select(item => item.ToViewModel());


                response.Message = String.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 28
0
        public IActionResult Default()
        {
            HomeViewModel             model         = new HomeViewModel();
            ListModelResponse <Event> routeResponse = _context.GetUserEvents(_userManager.GetUserId(User));

            if (routeResponse.DidError == true || routeResponse == null)
            {
                if (routeResponse == null)
                {
                    return(View("Error"));
                }
                Error er = new Error(routeResponse.ErrorMessage);
                return(View("Error"));
            }
            ListModelResponse <Route> eventResponse = _routeContext.GetUserRoutes(_userManager.GetUserId(User));

            if (eventResponse.DidError == true || eventResponse == null)
            {
                if (eventResponse == null)
                {
                    return(View("Error"));
                }
                Error er = new Error(eventResponse.ErrorMessage);
                return(View("Error"));
            }
            int nrEvents = eventResponse.Model.Count();
            int nrRoutes = routeResponse.Model.Count();

            model.NumberOfEvents = nrEvents;
            model.NumberOfRoutes = nrRoutes;
            return(View(model));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> UserDetail([FromBody] Search search)
        {
            //TODO: Handle error in the middleware and add try catch there
            IListModelResponse <User> response = new ListModelResponse <User>();

            try
            {
                _logger.LogInformation(entities.LoggingEvents.ListItems, "respository: {0}", _userRepository);

                if (search.TotalCount == 0)
                {
                    response.TotalCount = _userRepository.UserTotalCount();
                }
                List <User> users = await _userRepository.GetUsers(search);

                response.Model   = users;
                response.Message = "Listed users successfully";
            }
            catch (Exception ex)
            {
                _logger.LogInformation(entities.LoggingEvents.ListItems, "Exception:{0}", ex);

                response.IsError      = true;
                response.ErrorMessage = "Some Error occured, Please contact to Administrator";
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Ejemplo n.º 30
0
        public async Task <IListModelResponse <LeagueDto> > GetTeamLeaguesAsync(int teamId)
        {
            Logger?.LogInformation($"{nameof(GetTeamLeaguesAsync)} has been invoked");

            var response = new ListModelResponse <LeagueDto>();

            try
            {
                var team = await TeamRepository.GetItemByIdAsync(teamId);

                if (team == null)
                {
                    throw new FlmException($"Team with id={teamId} doesn't exist");
                }

                var query = LeagueRepository.GetTeamLeagueAssignments()
                            .Where(assignment => assignment.TeamId == teamId)
                            .Select(assignment => assignment.League);

                response.Model = await query.ProjectTo <LeagueDto>().ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }