Exemplo n.º 1
0
        public POModel Create(PO_Header po)
        {
            var     mapper = MapInit.MapInitialize().CreateMapper();
            POModel dto    = mapper.Map <POModel>(po);

            dto.Url = _UrlHelper.Link("PO", new { id = po.PONumber });
            return(dto);
        }
Exemplo n.º 2
0
 public StudentBaseModel CreateSummary(Students student)
 {
     return(new StudentBaseModel()
     {
         Url = _UrlHelper.Link("Students", new { userName = student.UserName }),
         Id = student.Id,
         FirstName = student.FirstName,
         LastName = student.LastName,
         Gender = student.Gender,
         EnrollmentsCount = student.Enrollments.Count(),
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Generates a fully qualified URL for the specified route values.
 /// </summary>
 /// <param name="urlHelper">The URL helper.</param>
 /// <param name="routeName">Name of the route.</param>
 /// <param name="controller">The controller.</param>
 /// <param name="mainArgument">The main argument.</param>
 /// <returns>
 /// Returns a fully-qualified URL.
 /// </returns>
 public static string Link(this System.Web.Http.Routing.UrlHelper urlHelper, string routeName,
                           string controller, string mainArgument = null)
 {
     Throw.IfArgumentNull(urlHelper, "urlHelper");
     Throw.IfArgumentNullOrEmpty(routeName, "routeName");
     Throw.IfArgumentNullOrEmpty(controller, "controller");
     return(urlHelper.Link(routeName, new { controller = controller, mainArgument = mainArgument }));
 }
Exemplo n.º 4
0
        public static List <LinkModel> SetLinks(System.Web.Http.Routing.UrlHelper urlHelper, string routeName, string controller, string method, int id = 0)
        {
            object           route = null;
            List <LinkModel> links = new List <LinkModel>();

            switch (controller.ToUpper())
            {
            case ("INSTRUCTORS"):
                switch (method.ToUpper())
                {
                case "GET":
                case "POST":
                case "DELETE":
                    route = new { controller = controller };
                    links.Add(new LinkModel("get instructors", urlHelper.Link(routeName, route), RestRequestVerb.GET));
                    links.Add(new LinkModel("post instructor", urlHelper.Link(routeName, route), RestRequestVerb.POST));
                    if (id > 0)
                    {
                        route = new { controller = controller, id = id };
                        links.Add(new LinkModel("get instructor", urlHelper.Link(routeName, route), RestRequestVerb.GET));
                        links.Add(new LinkModel("delete instructor", urlHelper.Link(routeName, route), RestRequestVerb.DELETE));
                    }

                    break;
                }
                break;

            case ("CLASSES"):
                switch (method.ToUpper())
                {
                case "GET":
                case "POST":
                case "DELETE":
                    route = new { controller = controller };
                    links.Add(new LinkModel("get classes", urlHelper.Link(routeName, route), RestRequestVerb.GET));
                    links.Add(new LinkModel("post classes", urlHelper.Link(routeName, route), RestRequestVerb.POST));
                    if (id > 0)
                    {
                        route = new { controller = controller, id = id };
                        links.Add(new LinkModel("get class", urlHelper.Link(routeName, route), RestRequestVerb.GET));
                        links.Add(new LinkModel("delete class", urlHelper.Link(routeName, route), RestRequestVerb.DELETE));
                    }

                    break;
                }
                break;

            default:
                break;
            }

            return(links);
        }
 public CourseModel Create(Course course)
 {
     return(new CourseModel()
     {
         Id = course.Id,
         Url = _UrlHelper.Link("Courses", new { id = course.Id }),
         Name = course.Name,
         Duration = course.Duration,
         Description = course.Description,
         Tutor = Create(course.CourseTutor),
         Subject = Create(course.CourseSubject)
     });
 }
    public static string RouteUrl(string routeName, object routeValues = null)
    {
        var url = String.Empty;

        try
        {
            var helper = new System.Web.Http.Routing.UrlHelper();
            return(helper.Link(routeName, routeValues));
        }
        catch
        {
            return(url);
        }
    }
Exemplo n.º 7
0
 public CompanyModel Create(Company company)
 {
     return(new CompanyModel()
     {
         Url = _UrlHelper.Link("Companies", new { id = company.Id }),
         Id = company.Id,
         Code = company.Code,
         Name = company.Name,
         Address = company.Address,
         Website = company.Website,
         Phone_Number = company.Phone_Number,
         //CompanyEmployees = Create(company.CompanyEmployees)
     });
 }
Exemplo n.º 8
0
        public async Task <IHttpActionResult> Get(string fields = null,
                                                  string sort   = "NickName",
                                                  string userId = null,
                                                  int page      = 1,
                                                  int pageSize  = maxPageSize)
        {
            try
            {
                Guid userIdGuid;
                Guid?Id = null;
                if (Guid.TryParse(userId, out userIdGuid))
                {
                    Id = userIdGuid;
                }
                IQueryable <User> users = await _repository.GetUsersAsync(Id);

                List <string> lstOfFields = new List <string>();

                if (fields != null)
                {
                    lstOfFields = fields.ToLower().Split(',').ToList();
                }

                users = users.ApplySort(sort)
                        .Where(eg => (userId == null || eg.UserId == Id));

                // ensure the page size isn't larger than the maximum.
                if (pageSize > maxPageSize)
                {
                    pageSize = maxPageSize;
                }

                // calculate data for metadata
                var totalCount = users.Count();
                var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

                var urlHelper = new System.Web.Http.Routing.UrlHelper(Request);
                var prevLink  = page > 1 ? urlHelper.Link("UsersList",
                                                          new
                {
                    page     = page - 1,
                    pageSize = pageSize,
                    sort     = sort,
                    fields   = fields,
                    userId   = userId
                }) : "";
                var nextLink = page < totalPages?urlHelper.Link("UsersList",
                                                                new
                {
                    page     = page + 1,
                    pageSize = pageSize,
                    sort     = sort,
                    fields   = fields,
                    userId   = userId
                }) : "";


                var paginationHeader = new
                {
                    currentPage      = page,
                    pageSize         = pageSize,
                    totalCount       = totalCount,
                    totalPages       = totalPages,
                    previousPageLink = prevLink,
                    nextPageLink     = nextLink
                };

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


                // return result
                return(Ok(users
                          .Skip(pageSize * (page - 1))
                          .Take(pageSize)
                          .ToList()
                          .Select(eg => _uFactory.CreateDataShapedObject(eg, lstOfFields))));
            }
            catch (Exception e)
            {
                //todo logghiamo ?
                return(InternalServerError());
            }
        }