Exemplo n.º 1
0
        public IHttpActionResult GetProductsById(int id)
        {
            ProductDTO productsseller = null;

            using (var ctx = new OSRSEntities())
            {
                productsseller = ctx.Products
                                 .Where(s => s.product_id == id)
                                 .Select(s => new ProductDTO()
                {
                    product_id       = s.product_id,
                    userid           = s.userid,
                    product_name     = s.product_name,
                    product_category = s.product_category,
                    price            = s.price
                }).FirstOrDefault <ProductDTO>();
            }

            if (productsseller == null)
            {
                return(NotFound());
            }

            return(Ok(productsseller));
        }
Exemplo n.º 2
0
        public IHttpActionResult ValidateUser(string username, string password, int usertype)
        {
            IList <UsertableDTO> users = null;

            using (var ctx = new OSRSEntities())
            {
                users = ctx.UserTables.Include("RoleType")
                        .Where(
                    u => u.username == username &&
                    u.password == password &&
                    u.usertype == usertype
                    )
                        .Select(u => new UsertableDTO()
                {
                    name           = u.name,
                    username       = u.username,
                    password       = u.password,
                    email          = u.email,
                    contact_number = u.contact_number,
                    userid         = u.userid,
                    usertype       = new RoletypeDTO()
                    {
                        roleid    = u.RoleType.roleid,
                        user_type = u.RoleType.user_type
                    }
                }).ToList <UsertableDTO>();
            }

            if (users.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(users));
        }
Exemplo n.º 3
0
        //update user details
        //implement edit method on client side
        public IHttpActionResult Put(UsertableDTO user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new OSRSEntities())
            {
                var existingUser = ctx.UserTables.Where(u => u.userid == user.userid)
                                   .FirstOrDefault <UserTable>();

                if (existingUser != null)
                {
                    existingUser.name           = user.name;
                    existingUser.password       = user.password;
                    existingUser.email          = user.email;
                    existingUser.contact_number = user.contact_number;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
Exemplo n.º 4
0
        //2
        public IHttpActionResult Put(ProductDTO product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new OSRSEntities())
            {
                var existingproducts = ctx.Products.Where(s => s.product_id == product.product_id)
                                       .FirstOrDefault <Product>();

                if (existingproducts != null)
                {
                    existingproducts.product_category = product.product_category;
                    existingproducts.product_name     = product.product_name;
                    existingproducts.price            = product.price;
                    ctx.SaveChanges();
                    return(Ok());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult GetAllOrderDetails()
        {
            IList <ViewOrderDTO> order = null;

            using (var ctx = new OSRSEntities())
            {
                order = ctx.OrderItemMappings
                        .Select(s => new ViewOrderDTO()
                {
                    name             = s.OrderTable.UserTable.name,
                    product_name     = s.Product.product_name,
                    product_category = s.Product.product_category,

                    userid        = s.OrderTable.userid,
                    order_id      = s.order_id,
                    order_date    = s.OrderTable.order_date,
                    shipping_date = s.OrderTable.shipping_date,
                    amount        = s.OrderTable.amount,
                }).ToList <ViewOrderDTO>();
            }

            if (order.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(order));
        }
Exemplo n.º 6
0
        //gets user by userid
        //fetches user details for updating
        //same as GetUserByID
        public IHttpActionResult GetUserDetailsByID(int userid)
        {
            UsertableDTO user = null;

            using (var ctx = new OSRSEntities())
            {
                user = ctx.UserTables.Include("RoleType")
                       .Where(
                    u => u.userid == userid
                    )
                       .Select(u => new UsertableDTO()
                {
                    name           = u.name,
                    username       = u.username,
                    password       = u.password,
                    email          = u.email,
                    contact_number = u.contact_number,
                    userid         = u.userid,
                    usertype       = new RoletypeDTO()
                    {
                        roleid    = u.RoleType.roleid,
                        user_type = u.RoleType.user_type
                    }
                }).FirstOrDefault <UsertableDTO>();
            }

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }
Exemplo n.º 7
0
        //2
        //need some changes
        public IHttpActionResult Delete(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid Product id"));
            }

            using (var ctx = new OSRSEntities())
            {
                var deleteproduct = ctx.Products
                                    .Where(s => s.product_id == id)
                                    .FirstOrDefault();
                ctx.Entry(deleteproduct).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }
Exemplo n.º 8
0
        public IHttpActionResult AddPaymentDetails(PaymentDTO payment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            using (var ctx = new OSRSEntities())
            {
                ctx.addPaymentTransactions(payment.nameOnCard,
                                           payment.cardNumber,
                                           payment.cvv,
                                           payment.netBankingName,
                                           payment.order_id,
                                           payment.userid,
                                           payment.expiryDate,
                                           payment.amount);
                ctx.SaveChanges();
            }
            return(Ok());
        }
Exemplo n.º 9
0
        //2
        public IHttpActionResult PostNewProducts(ProductDTO product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            using (var ctx = new OSRSEntities())
            {
                ctx.Products.Add(new Product()
                {
                    userid           = product.userid,
                    product_category = product.product_category,
                    product_name     = product.product_name,
                    price            = product.price
                });

                ctx.SaveChanges();
            }

            return(Ok());
        }
Exemplo n.º 10
0
        public IHttpActionResult GetViewCart(int id)
        {
            List <CartItemsDTO> cartItems = new List <CartItemsDTO>();
            var context = new OSRSEntities();

            try
            {
                //var query = from p in context.Products
                //            join c in context.CartItemMappings on
                //            p.product_id equals c.product_id
                //            join d in context.Carts on c.cart_id equals d.cart_id
                //            where p.userid == id
                //            select new { p.product_name, p.price, p.product_category, c.cart_id, c.quantity, c.no_of_renting_days, Total = p.price * c.quantity };
                var query = context.getcartitemmappingv3(id);
                foreach (var item in query)
                {
                    CartItemsDTO cartitem = new CartItemsDTO();
                    cartitem.product_name       = item.product_name;
                    cartitem.price              = item.price;
                    cartitem.product_category   = item.product_category;
                    cartitem.quantity           = item.quantity;
                    cartitem.no_of_renting_days = item.no_of_renting_days;
                    cartitem.cartid             = item.cart_id;
                    //// cartitem.productid = item.product_id;
                    cartitem.total = item.total;
                    cartItems.Add(cartitem);
                }
                if (query == null)
                {
                    return(NotFound());
                }
                return(Ok(cartItems));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 11
0
        public IHttpActionResult AddUser(UsertableDTO userTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            using (var ctx = new OSRSEntities())
            {
                ctx.UserTables.Add(new UserTable()
                {
                    userid         = userTable.userid,
                    name           = userTable.name,
                    username       = userTable.username,
                    password       = userTable.password,
                    email          = userTable.email,
                    contact_number = userTable.contact_number,
                    usertype       = userTable.usertype.roleid
                });
                ctx.SaveChanges();
            }
            return(Ok());
        }
Exemplo n.º 12
0
        //2
        public IHttpActionResult GetProductsByUserId(int userid)
        {
            IList <OSRSWebAPI.Models.ProductDTO> productsseller = null;

            using (var ctx = new OSRSEntities())
            {
                //productsseller = ctx.Products
                //            .Select(s => new ProductSellerDTO()
                //            {
                //                product_id=s.product_id,
                //                userid = s.userid,
                //                product_category = s.product_category,
                //                product_name = s.product_name,
                //                price= s.price
                //            }).ToList<ProductSellerDTO>();

                //added userid to filter
                productsseller = ctx.Products
                                 .Where(s => s.userid == userid)
                                 .Select(s => new ProductDTO()
                {
                    product_id       = s.product_id,
                    userid           = s.userid,
                    product_category = s.product_category,
                    product_name     = s.product_name,
                    price            = s.price
                }).ToList <ProductDTO>();
            }

            if (productsseller.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(productsseller));
        }
Exemplo n.º 13
0
        //public IHttpActionResult GetAllUsers()
        //{
        //    List<ProductDTO> products = new List<ProductDTO>();

        //    using (var ctx = new OSRSEntities())
        //    {

        //        var query= ctx.ViewProducts(8);
        ////         public int product_id { get; set; }
        ////public int userid { get; set; }
        ////public string product_name { get; set; }
        ////public double price { get; set; }
        ////public string product_category { get; set; }
        //        foreach(var item in query)
        //        {
        //            ProductDTO product = new ProductDTO();
        //            product.product_id = item.Product_ID;
        //            product.product_name = item.Product_Name;
        //            product.prxice = item.Price;
        //            products.Add(product);
        //        }
        //        //if (products.Count == 0)
        //        //{
        //        //    return NotFound();
        //        //}

        //        return Ok(products);
        //    }
        //}
        public IHttpActionResult GetAllProducts()
        {
            IList <ProductDTO> productsseller = null;

            using (var ctx = new OSRSEntities())
            {
                productsseller = ctx.Products
                                 .Select(s => new ProductDTO()
                {
                    product_id       = s.product_id,
                    userid           = s.userid,
                    product_category = s.product_category,
                    product_name     = s.product_name,
                    price            = s.price
                }).ToList <ProductDTO>();
            }

            if (productsseller.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(productsseller));
        }