Ejemplo n.º 1
0
        public HttpResponseMessage Get(string id)
        {
            HttpResponseMessage responseMessage;
            JSend json;
            var   token   = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First();
            var   pageVal = GetPageNumberAndElementNumber();
            var   pageNr  = pageVal[0];
            var   perPage = pageVal[1];
            var   state   = GetState();

            var list = new List <UtilityDTO>();

            list = _carsUtilitiesModel.GetAllUtilities(null);

            if (list.Count > 0)
            {
                json            = new JSendData <UtilityDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 2
0
        // GET: api/Orders
        public HttpResponseMessage GetOrders()
        {
            HttpResponseMessage responseMessage;
            var token  = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First();
            var userId = db.Tokens.First(u => u.TokenString.Equals(token))?.UserId;

            var orderList         = db.Orders.Where(o => o.UserId == userId).OrderByDescending(o => o.Date).ToList();
            var responseOrderList = new List <ListOrdersDTO>();

            foreach (var order in orderList)
            {
                responseOrderList.Add(new ListOrdersDTO
                {
                    OrderId = order.OrderId,
                    Total   = (order.Subtotal + order.Shipping) + " " + order.Currency,
                    Date    = string.Format("{0:f}", order.Date)
                });
            }

            JSend json = new JSendData <ListOrdersDTO>("success", responseOrderList);

            responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);

            return(responseMessage);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage GetOrders(bool deliveredFilter)
        {
            HttpResponseMessage responseMessage;
            List <Orders>       orderList;

            if (deliveredFilter)
            {
                orderList = db.Orders.Where(o => o.Sent == true).OrderByDescending(o => o.Date).ToList();
            }
            else
            {
                orderList = db.Orders.Where(o => o.Sent != true).OrderByDescending(o => o.Date).ToList();
            }

            var responseOrderList = new List <ListOrdersDTO>();

            foreach (var order in orderList)
            {
                responseOrderList.Add(new ListOrdersDTO
                {
                    OrderId = order.OrderId,
                    Total   = (order.Subtotal + order.Shipping) + " " + order.Currency,
                    Date    = string.Format("{0:f}", order.Date)
                });
            }

            JSend json = new JSendData <ListOrdersDTO>("success", responseOrderList);

            responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);

            return(responseMessage);
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage responseMessage;
            JSend  json;
            string token = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First();

            int[]  pageVal  = GetPageNumberAndElementNumber();
            int    page_nr  = pageVal[0];
            int    per_page = pageVal[1];
            string state    = GetState();

            List <FormDTO> list = formModel.GetAllForms(token, page_nr, per_page, state);

            if (list.Count > 0)
            {
                json            = new JSendData <FormDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Voted(string id)
        {
            HttpResponseMessage responseMessage;
            JSend json;

            int[]  pageVal  = GetPageNumberAndElementNumber();
            int    page_nr  = pageVal[0];
            int    per_page = pageVal[1];
            string state    = GetState();

            List <FormDTO> list = new List <FormDTO>();

            list = formModel.GetVotedForms(id, page_nr, per_page, state);

            if (list.Count > 0)
            {
                json            = new JSendData <FormDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 6
0
        // GET: api/Products
        public HttpResponseMessage GetProducts(int top, int from, string gender, string type, string lang, string currency)
        {
            HttpResponseMessage responseMessage;
            var productList = new List <Products>();

            if (type == "intro")
            {
                productList = db.Products.OrderBy(p => p.ProductId).Skip(Math.Max(0, db.Products.Count() - top)).Take(top).ToList();
            }
            else
            {
                productList = db.Products.Where(p => p.Gender == gender && p.Type == type).OrderBy(p => p.ProductId).Skip(from).Take(top).ToList();
            }

            //Random rnd = new Random();
            //for (int i = 0; i < 3; i++)
            //{
            //    productList.Add(new Products
            //    {
            //        Name_RO = "Name_RO" + i,
            //        Name_EN = "Name_EN" + i,
            //        Name_IT = "Name_IT" + i,
            //        Price = i + 1,
            //        ProductId = rnd.Next(1, 4)
            //    });
            //}

            List <ProductInfo> result = new List <ProductInfo>();

            foreach (var product in productList)
            {
                result.Add(new ProductInfo
                {
                    Name      = ComputeName(product, lang),
                    Price     = GetCurrencyPrice(product, currency),
                    ProductId = product.ProductId,
                    Image     = new ProductsImagesController().GetProductsImage(product.ProductId)
                });
            }

            JSend json = new JSendData <ProductInfo>("success", result);

            responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);

            return(responseMessage);
        }
Ejemplo n.º 7
0
        public HttpResponseMessage Utilitiescar(int id)
        {
            HttpResponseMessage responseMessage;
            JSend json;
            var   list = _carModel.GetAllCarUtilities(id);

            if (list.Count > 0)
            {
                json            = new JSendData <UtilityDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 8
0
        public HttpResponseMessage Usernames(int id)
        {
            HttpResponseMessage responseMessage;
            JSend json;
            List <UsernameDTO> list = userModel.GetAllUsernames();

            if (list.Count > 0)
            {
                json            = new JSendData <UsernameDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NoContent, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 9
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage responseMessage;
            JSend json;
            List <CategoryDTO> list = categoryModel.GetAllCategories();

            if (list.Count > 0)
            {
                json            = new JSendData <CategoryDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 10
0
        public HttpResponseMessage GetCar(int id)
        {
            HttpResponseMessage responseMessage;
            JSend json;
            var   carDetails = _carModel.GetCarDetails(id);

            if (null != carDetails)
            {
                json = new JSendData <CarDetailsDTO>("success", new List <CarDetailsDTO> {
                    carDetails
                });
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 11
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage responseMessage;
            JSend json;
            var   pageVal = GetPageNumberAndElementNumber();
            var   pageNr  = pageVal[0];
            var   perPage = pageVal[1];
            var   list    = _userModel.GetAllUsers(pageNr, perPage);

            if (list.Count > 0)
            {
                json            = new JSendData <UserDetailDTO>("success", list);
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 12
0
        public HttpResponseMessage GetCartProducts(GetCartProductsDTO request)
        {
            HttpResponseMessage responseMessage;
            var productList = db.Products.Where(p => request.ProductIds.Contains(p.ProductId)).ToList();

            //var productList = new List<Products>();
            //Random rnd = new Random();
            //for (int i = 0; i < request.ProductIds.Count; i++)
            //{
            //    productList.Add(new Products
            //    {
            //        Name_RO = "Name_RO" + i,
            //        Name_EN = "Name_EN" + i,
            //        Name_IT = "Name_IT" + i,
            //        Price = i + 1,
            //        ProductId = request.ProductIds[i]
            //    });
            //}

            var result = new List <ProductInfo>();

            foreach (var product in productList)
            {
                result.Add(new ProductInfo
                {
                    Name      = ComputeName(product, request.Lang),
                    Price     = GetCurrencyPrice(product, request.Currency),
                    ProductId = product.ProductId,
                    Image     = new ProductsImagesController().GetProductsImage(product.ProductId)
                });
            }

            JSend json = new JSendData <ProductInfo>("success", result);

            responseMessage = Request.CreateResponse(HttpStatusCode.OK, json);

            return(responseMessage);
        }