Ejemplo n.º 1
0
        /// <summary>
        /// Get all product/ service categories
        /// </summary>
        /// <param name="isService">categories for service if true; else for product</param>
        /// <returns></returns>
        public List <CATEGORy> GetAllCategories(bool isService)
        {
            List <CATEGORy> categories = new List <CATEGORy>();

            try
            {
                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        categories = (from c in db.CATEGORIES
                                      where c.SERVICE.Value == isService
                                      select c).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return(categories);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get all services for a category
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List <SERVICE> GetAllServicesByCategory(Guid?categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("CategoryId", "CategoryId can not be null");
                }

                List <SERVICE> services = new List <SERVICE>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        services = (from p in db.SERVICES
                                    where p.CATEGORYID == categoryId
                                    select p).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }

                return(services);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public bool AddNewProductOrder(ORDERPRODUCT order)
        {
            try
            {
                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.ORDERPRODUCTS.Add(order);

                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get all product/ service categories
 /// </summary>
 /// <param name="isService">categories for service if true; else for product</param>
 /// <returns></returns>
 public List<CATEGORy> GetAllCategories(bool isService)
 {
     List<CATEGORy> categories = new List<CATEGORy>();
     try
     { 
        using(APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
         {
             try
             {
                 categories = (from c in db.CATEGORIES
                                              where c.SERVICE.Value == isService
                                              select c).ToList();
             }
             catch (System.Data.DataException e)
             {
                 throw new Exception(e.InnerException.InnerException.Message);
             }
             catch(ArgumentNullException e)
             {
             }
         }
         return categories;
     }
     catch(Exception e)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Add new product/ service category
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public Guid AddNewCategory(CATEGORy category)
        {
            try
            {
                if(category == null)
                    throw new ArgumentNullException("Category", "Category can not be null");

                // check if all required fields are present
                if(category.NAME == null || !category.SERVICE.HasValue)
                    throw new ArgumentException("Category", "Some mandatory parameters required to add a new category are missing");

                if (!category.ID.HasValue || category.ID.Value == Guid.Empty)
                    category.ID = Guid.NewGuid();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CATEGORIES.Add(category);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return category.ID.Value;
            }
            catch (Exception e)
            {
                throw;
            }

        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get all product orders for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List <ORDER> GetAllProductOrdersById(Guid?categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("CategoryId", "CategoryId can not be null");
                }

                List <ORDER> products = new List <ORDER>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.ORDERS
                                    where p.BUYERID == categoryId && p.ISACTIVE == true && p.ISSERVICE == false
                                    select p).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return(products);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get all products for a category
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List<PRODUCT> GetAllProductsByCategory(Guid? categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                    throw new ArgumentNullException("CategoryId", "CategoryId can not be null");

                List<PRODUCT> products = new List<PRODUCT>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.PRODUCTS
                                  where p.CATEGORYID == categoryId
                                  select p).ToList();                
                     }
                    catch(System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch(ArgumentNullException e)
                    {
                    }
                }
                return products;
            }
            catch(Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        public bool AddNewProductOrder(ORDERPRODUCT order)
        {
            try
            {


                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.ORDERPRODUCTS.Add(order);

                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                        return false;
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// delete product from cart
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteProduct(Guid?id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("ID", "ID can not be null");
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        var product = (from s in db.CARTs
                                       where s.ID == id
                                       select s).Single();
                        db.CARTs.Remove(product);
                        db.SaveChanges();
                        return(true);
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 10
0
        public Guid AddNewOrder(ORDER order)
        {
            try
            {
                if (order == null)
                    throw new ArgumentNullException("Product", "Product can not be null");

                // check if all required fields are present
                if ((order.BUYERID == null || order.BUYERID == Guid.Empty))
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");

                if (order.ID == null || order.ID == Guid.Empty)
                    order.ID = Guid.NewGuid();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.ORDERS.Add(order);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return order.ID;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get all products for a Cart
        /// </summary>
        /// <param name="buyerId"></param>
        /// <returns></returns>
        public List<CartProduct> GetAllCartProducts(Guid? buyerId)
        {
            try
            {
                if (!buyerId.HasValue || buyerId.Value == Guid.Empty)
                    throw new ArgumentNullException("BuyerID", "BuyerId can not be null");

                List<CartProduct> products = new List<CartProduct>();
                
                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.CARTs
                                    join pr in db.PRODUCTS on p.PRODUCTID equals pr.ID
                                    where p.BUYERID == buyerId
                                    select new CartProduct { ID = p.ID, PRODUCTID = p.PRODUCTID, QUANTITY = p.QUANTITY, BUYERID = p.BUYERID, ISACTIVE = p.ISACTIVE, ProductName = pr.NAME,Price = (Decimal)pr.PRICE }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return products;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add new product to Cart
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddProductInCart(CART product)
        {
            try
            {
                CART productcart = null;
                product.ISACTIVE = true;
                if (product == null)
                {
                    throw new ArgumentNullException("Product", "Product can not be null");
                }

                // check if all required fields are present
                if ((product.PRODUCTID == null || product.PRODUCTID == Guid.Empty) || product.QUANTITY == null ||
                    (product.BUYERID == null || product.BUYERID == Guid.Empty))
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                }
                try
                {
                    using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                    {
                        productcart = (from p in db.CARTs
                                       where p.BUYERID == product.BUYERID && p.PRODUCTID == product.PRODUCTID
                                       select p).Single();
                    }
                    return(productcart.ID);
                }
                catch (Exception e)
                {
                }

                if (product.ID == null || product.ID == Guid.Empty)
                {
                    product.ID = Guid.NewGuid();
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CARTs.Add(product);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(product.ID);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 13
0
        // TODO : TO REVISIT User should be able to add 1 review (rating and comment) for a product/ service
        /// <summary>
        /// Add a new review for a product/ service by a user
        /// </summary>
        /// <param name="userReview"></param>
        /// <returns></returns>
        public Guid AddNewReview(REVIEW userReview)
        {
            try
            {
                if (userReview == null)
                {
                    throw new ArgumentNullException("UserReview", "UserReview can not be null");
                }

                if ((!userReview.PRODUCTID.HasValue || userReview.PRODUCTID.Value == Guid.Empty) && (!userReview.SERVICEID.HasValue || userReview.SERVICEID.Value == Guid.Empty))
                {
                    throw new ArgumentException("Both PRODUCTID SERVICEID can not be null together", "UserReview");
                }

                if ((userReview.PRODUCTID.HasValue && userReview.PRODUCTID.Value != Guid.Empty) && (userReview.SERVICEID.HasValue && userReview.SERVICEID.Value != Guid.Empty))
                {
                    throw new ArgumentException("Both PRODUCTID SERVICEID can not have values together", "UserReview");
                }

                if (!userReview.REVIEWERID.HasValue || userReview.REVIEWERID.Value == Guid.Empty)
                {
                    throw new ArgumentException("REVIEWERID can not be null", "UserReview");
                }

                if (userReview.RATING == null && string.IsNullOrEmpty(userReview.COMMENTS))
                {
                    return(Guid.Empty);
                }

                if (!userReview.ID.HasValue || userReview.ID.Value == Guid.Empty)
                {
                    userReview.ID = Guid.NewGuid();
                }
                userReview.REVIEWDATE = DateTime.Now;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.REVIEWS.Add(userReview);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }
                return(userReview.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add new product to Cart
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddProductInCart(CART product)
        {
            try
            {
                CART productcart=null;
                product.ISACTIVE = true;
                if (product == null)
                    throw new ArgumentNullException("Product", "Product can not be null");

                // check if all required fields are present
                if ((product.PRODUCTID == null || product.PRODUCTID == Guid.Empty) || product.QUANTITY == null ||
                    (product.BUYERID == null || product.BUYERID == Guid.Empty))
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                try
                {
                    using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                    {
                        productcart = (from p in db.CARTs
                                       where p.BUYERID == product.BUYERID && p.PRODUCTID == product.PRODUCTID
                                       select p).Single();
                    }
                    return productcart.ID;
                }
                catch (Exception e)
                {

                }

                if (product.ID==null || product.ID == Guid.Empty)
                    product.ID = Guid.NewGuid();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CARTs.Add(product);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return product.ID;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 15
0
 public IHttpActionResult Login()
 {
    USER ui = null;
     try
     {
         APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities();
         ui=  
            (from userinfo in db.USERS  select userinfo)
                .ToList()[0];
     }
     catch (Exception e)
     {
         return this.NotFound();
     }
     return Ok(ui);
 }
Ejemplo n.º 16
0
        public IHttpActionResult Login()
        {
            USER ui = null;

            try
            {
                APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities();
                ui =
                    (from userinfo in db.USERS select userinfo)
                    .ToList()[0];
            }
            catch (Exception e)
            {
                return(this.NotFound());
            }
            return(Ok(ui));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Add new service
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public Guid AddNewService(SERVICE service)
        {
            try
            {
                if (service == null)
                {
                    throw new ArgumentNullException("Service", "Service can not be null");
                }

                // check if all required fields are present
                if ((!service.CATEGORYID.HasValue || service.CATEGORYID.Value == Guid.Empty) || service.NAME == null ||
                    !service.PRICE.HasValue || (!service.SELLERID.HasValue || service.SELLERID.Value == Guid.Empty))
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new service are missing", "Service");
                }

                if (!service.ID.HasValue || service.ID.Value == Guid.Empty)
                {
                    service.ID = Guid.NewGuid();
                }

                service.AVGRATING     = 0;
                service.ISACTIVE      = true;
                service.NUMBEROFUSERS = 0;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.SERVICES.Add(service);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(service.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 18
0
        // TODO : how to add image url
        /// <summary>
        /// Add new product
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddNewProduct(PRODUCT product)
        {
            try
            {
                if (product == null)
                {
                    throw new ArgumentNullException("Product", "Product can not be null");
                }

                // check if all required fields are present
                if ((!product.CATEGORYID.HasValue || product.CATEGORYID.Value == Guid.Empty) || product.NAME == null ||
                    !product.PRICE.HasValue || (!product.SELLERID.HasValue || product.SELLERID.Value == Guid.Empty))
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                }

                if (!product.ID.HasValue || product.ID.Value == Guid.Empty)
                {
                    product.ID = Guid.NewGuid();
                }

                product.AVGRATING    = 0;
                product.QUANTITYSOLD = 0;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.PRODUCTS.Add(product);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(product.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Add new product to Cart
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddServiceInOrder(SERVICEORDER product)
        {
            try
            {
                if (product == null)
                {
                    throw new ArgumentNullException("Service", "Service can not be null");
                }

                // check if all required fields are present
                if ((product.SERVICEID == null || product.SERVICEID == Guid.Empty) ||
                    (product.BUYERID == null || product.BUYERID == Guid.Empty))
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                }
                try
                {
                    using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                    {
                        try
                        {
                            db.SERVICEORDERs.Add(product);
                            db.SaveChanges();
                        }
                        catch (System.Data.DataException e)
                        {
                            throw new Exception(e.InnerException.InnerException.Message);
                        }
                    }
                    return(product.SERVICEID);
                }
                catch (Exception e)
                {
                    throw new Exception(e.InnerException.InnerException.Message);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.InnerException.InnerException.Message);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Add new product/ service category
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public Guid AddNewCategory(CATEGORy category)
        {
            try
            {
                if (category == null)
                {
                    throw new ArgumentNullException("Category", "Category can not be null");
                }

                // check if all required fields are present
                if (category.NAME == null || !category.SERVICE.HasValue)
                {
                    throw new ArgumentException("Category", "Some mandatory parameters required to add a new category are missing");
                }

                if (!category.ID.HasValue || category.ID.Value == Guid.Empty)
                {
                    category.ID = Guid.NewGuid();
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CATEGORIES.Add(category);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(category.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 21
0
        public Guid AddNewOrder(ORDER order)
        {
            try
            {
                if (order == null)
                {
                    throw new ArgumentNullException("Product", "Product can not be null");
                }

                // check if all required fields are present
                if ((order.BUYERID == null || order.BUYERID == Guid.Empty))
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                }

                if (order.ID == null || order.ID == Guid.Empty)
                {
                    order.ID = Guid.NewGuid();
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.ORDERS.Add(order);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(order.ID);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get user by email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public USER GetUserById(String email, String password)
        {
            try
            {
                if (email.Equals("") || email == null)
                {
                    throw new ArgumentNullException("EMAIL", "EMAIL ID can not be null");
                }

                USER user;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        user = (from p in db.USERS
                                where p.EMAILID == email && p.PASSWORD == password
                                select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        user = null;    // user not availble
                    }
                    catch (InvalidOperationException e)
                    {
                        user = null;    // multiple users available with same id
                    }
                }

                return(user);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Get user by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public USER GetUserById(Guid?id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("ID", "ID can not be null");
                }

                USER user;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        user = (from p in db.USERS
                                where p.ID == id
                                select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        user = null;    // user not availble
                    }
                    catch (InvalidOperationException e)
                    {
                        user = null;    // multiple users available with same id
                    }
                }

                return(user);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get service by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SERVICE GetServiceById(Guid?id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("ID", "ID can not be null");
                }

                SERVICE service;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        service = (from p in db.SERVICES
                                   where p.ID == id
                                   select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        service = null; // no such service
                    }
                    catch (InvalidOperationException e)
                    {
                        service = null;
                    }
                }
                return(service);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Get Service by seller id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List <SERVICE> GetAllServicesOfferedByMe(Guid?id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("ID", "ID can not be null");
                }

                List <SERVICE> product;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        product = (from p in db.SERVICES
                                   where p.SELLERID == id
                                   select p).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        product = null; // no such product
                    }
                    catch (InvalidOperationException e)
                    {
                        product = null; // multiple products with same id
                    }
                }
                return(product);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Get product by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PRODUCT GetProductById(Guid?id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("ID", "ID can not be null");
                }

                PRODUCT product;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        product = (from p in db.PRODUCTS
                                   where p.ID == id
                                   select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        product = null; // no such product
                    }
                    catch (InvalidOperationException e)
                    {
                        product = null; // multiple products with same id
                    }
                }
                return(product);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Add new service
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public Guid AddNewService(SERVICE service)
        {
            try
            {
                if (service == null)
                    throw new ArgumentNullException("Service", "Service can not be null");

                // check if all required fields are present
                if ((!service.CATEGORYID.HasValue || service.CATEGORYID.Value == Guid.Empty) || service.NAME == null ||
                    !service.PRICE.HasValue || (!service.SELLERID.HasValue || service.SELLERID.Value == Guid.Empty))
                    throw new ArgumentException("Some mandatory parameters required to add a new service are missing", "Service");

                if (!service.ID.HasValue || service.ID.Value == Guid.Empty)
                    service.ID = Guid.NewGuid();

                service.AVGRATING = 0;
                service.ISACTIVE = true;
                service.NUMBEROFUSERS = 0;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.SERVICES.Add(service);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return service.ID.Value;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 28
0
        // TODO : how to add image url
        /// <summary>
        /// Add new product
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddNewProduct(PRODUCT product)
        {
            try
            {
                if (product == null)
                    throw new ArgumentNullException("Product", "Product can not be null");

                // check if all required fields are present
                if ((!product.CATEGORYID.HasValue || product.CATEGORYID.Value == Guid.Empty)|| product.NAME == null || 
                    !product.PRICE.HasValue || (!product.SELLERID.HasValue || product.SELLERID.Value == Guid.Empty))
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                                
                if (!product.ID.HasValue || product.ID.Value == Guid.Empty)
                    product.ID = Guid.NewGuid();

                product.AVGRATING = 0;
                product.QUANTITYSOLD = 0;
               
                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.PRODUCTS.Add(product);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return product.ID.Value;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Get all Service order for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List <SubscribedService> GetAllSubscribedServiceById(Guid?categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("CategoryId", "OrderId can not be null");
                }

                List <SubscribedService> services = new List <SubscribedService>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        services = (from p in db.SERVICEORDERs
                                    join pr in db.SERVICES on p.SERVICEID equals pr.ID
                                    join seller in db.USERS on pr.SELLERID equals seller.ID
                                    where p.BUYERID == categoryId
                                    select new SubscribedService {
                            ID = pr.ID, Name = pr.NAME, Price = pr.PRICE, Details = pr.DETAILS, SellerName = seller.NAME, SellerContact = seller.CONTACTNUMBER, SellerPlace = seller.PLACE, SellerCity = seller.CITY
                        }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return(services);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Get all product of a order for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List <OrderProducts> GetAllProductForOrder(Guid?categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("CategoryId", "OrderId can not be null");
                }

                List <OrderProducts> products = new List <OrderProducts>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.ORDERPRODUCTS
                                    join pr in db.PRODUCTS on p.PRODUCTID equals pr.ID
                                    where p.ORDERID == categoryId
                                    select new OrderProducts {
                            QUANTITY = (int)p.QUANTITY, ProductName = pr.NAME, Price = (Decimal)pr.PRICE
                        }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return(products);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Get all products for a Cart
        /// </summary>
        /// <param name="buyerId"></param>
        /// <returns></returns>
        public List <CartProduct> GetAllCartProducts(Guid?buyerId)
        {
            try
            {
                if (!buyerId.HasValue || buyerId.Value == Guid.Empty)
                {
                    throw new ArgumentNullException("BuyerID", "BuyerId can not be null");
                }

                List <CartProduct> products = new List <CartProduct>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.CARTs
                                    join pr in db.PRODUCTS on p.PRODUCTID equals pr.ID
                                    where p.BUYERID == buyerId
                                    select new CartProduct {
                            ID = p.ID, PRODUCTID = p.PRODUCTID, QUANTITY = p.QUANTITY, BUYERID = p.BUYERID, ISACTIVE = p.ISACTIVE, ProductName = pr.NAME, Price = (Decimal)pr.PRICE
                        }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return(products);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Get all Service order for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List<SubscribedService> GetAllSubscribedServiceById(Guid? categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                    throw new ArgumentNullException("CategoryId", "OrderId can not be null");

                List<SubscribedService> services = new List<SubscribedService>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        services = (from p in db.SERVICEORDERs
                                    join pr in db.SERVICES on p.SERVICEID equals pr.ID
                                    join seller in db.USERS on pr.SELLERID equals seller.ID
                                    where p.BUYERID == categoryId
                                    select new SubscribedService { ID = pr.ID, Name=pr.NAME,Price = pr.PRICE,Details=pr.DETAILS,SellerName=seller.NAME,SellerContact=seller.CONTACTNUMBER,SellerPlace=seller.PLACE,SellerCity=seller.CITY }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return services;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// delete product
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteProduct(Guid? id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                    throw new ArgumentNullException("ID", "ID can not be null");

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        var product = (from s in db.PRODUCTS
                                       where s.ID == id
                                       select s).Single();
                        db.PRODUCTS.Remove(product);
                        db.SaveChanges();
                        return true;
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Get Service by seller id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<SERVICE> GetAllServicesOfferedByMe(Guid? id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                    throw new ArgumentNullException("ID", "ID can not be null");

                List<SERVICE> product;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        product = (from p in db.SERVICES
                                   where p.SELLERID == id
                                   select p).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        product = null; // no such product
                    }
                    catch (InvalidOperationException e)
                    {
                        product = null; // multiple products with same id
                    }
                }
                return product;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Get user by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public USER GetUserById(Guid? id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                    throw new ArgumentNullException("ID", "ID can not be null");

                USER user;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        user = (from p in db.USERS
                                 where p.ID == id
                                 select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch(ArgumentNullException e)
                    {
                        user = null;    // user not availble 
                    }
                    catch(InvalidOperationException e)
                    {
                        user = null;    // multiple users available with same id
                    }
                }

                return user;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Get all product of a order for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List<OrderProducts> GetAllProductForOrder(Guid? categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                    throw new ArgumentNullException("CategoryId", "OrderId can not be null");

                List<OrderProducts> products = new List<OrderProducts>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.ORDERPRODUCTS
                                    join pr in db.PRODUCTS on p.PRODUCTID equals pr.ID
                                    where p.ORDERID == categoryId
                                    select new OrderProducts { QUANTITY = (int)p.QUANTITY, ProductName = pr.NAME, Price = (Decimal)pr.PRICE }).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return products;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Edit buyer/ seller profile details
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool EditUserDetails(USER user)
        {
            try
            {
                if (user == null)
                {
                    throw new ArgumentNullException("User", "User can not be null");
                }

                if (user.ID == null)
                {
                    throw new ArgumentNullException("User", "User ID can not be null");
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        USER existingUser = (from u in db.USERS
                                             where u.ID == user.ID
                                             select u).Single();

                        if (user.ROLEID != null && existingUser.ROLEID != user.ROLEID)
                        {
                            throw new ArgumentException("ROLEID can not be changed using this EditUserDetails service");
                        }
                        if (user.USERNAME != null && existingUser.USERNAME != user.USERNAME)
                        {
                            throw new ArgumentException("USERNAME can never be modified");
                        }

                        if (user.NAME != null)
                        {
                            existingUser.NAME = user.NAME;
                        }
                        if (user.PASSWORD != null)
                        {
                            existingUser.PASSWORD = user.PASSWORD;
                        }
                        if (user.CONTACTNUMBER != null)
                        {
                            existingUser.CONTACTNUMBER = user.CONTACTNUMBER;
                        }
                        if (user.EMAILID != null)
                        {
                            existingUser.EMAILID = user.EMAILID;
                        }
                        if (user.PLACE != null)
                        {
                            existingUser.PLACE = user.PLACE;
                        }
                        if (user.CITY != null)
                        {
                            existingUser.CITY = user.CITY;
                        }
                        if (user.STATE != null)
                        {
                            existingUser.STATE = user.STATE;
                        }
                        if (user.PINCODE != null)
                        {
                            existingUser.PINCODE = user.PINCODE;
                        }

                        db.SaveChanges();
                        return(true);
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Add new Seller/ Buyer
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Guid AddNewUser(USER user)
        {
            try
            {
                if (user == null)
                {
                    throw new ArgumentNullException("User", "User can not be null");
                }

                if (user.ROLEID == (int)UserRoles.Admin)
                {
                    throw new ArgumentException("Admins can not be added using this service", "User");
                }

                // check if all required fields are present
                if (user.USERNAME == null || user.PASSWORD == null || user.NAME == null || user.GENDER == null || user.CONTACTNUMBER == null)
                {
                    throw new ArgumentException("Some mandatory parameters required to add a new user are missing", "User");
                }

                // by default, all users are buyers
                if (!user.ROLEID.HasValue)
                {
                    user.ROLEID = (int)UserRoles.Buyer;
                }

                // check if all additional required fields for seller are present
                if (user.ROLEID == (int)UserRoles.Seller &&
                    (user.EMAILID == null || user.PLACE == null || user.CITY == null || user.STATE == null || user.PINCODE == null))
                {
                    throw new ArgumentException("Some additional mandatory parameters required to add a new seller are missing", "User");
                }

                if (!user.ID.HasValue || user.ID.Value == Guid.Empty)
                {
                    user.ID = Guid.NewGuid();
                }

                //  user.ROLE.ROLENAME = "BUYER";

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.USERS.Add(user);
                        db.SaveChanges();
                    }

                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}",
                                                       validationError.PropertyName,
                                                       validationError.ErrorMessage);
                            }
                        }
                    }

                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(user.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 39
0
        // TODO : TO REVISIT User should be able to add 1 review (rating and comment) for a product/ service
        /// <summary>
        /// Add a new review for a product/ service by a user
        /// </summary>
        /// <param name="userReview"></param>
        /// <returns></returns>
        public Guid AddNewReview(REVIEW userReview)
        {
            try
            {
                if (userReview == null)
                    throw new ArgumentNullException("UserReview", "UserReview can not be null");

                if((!userReview.PRODUCTID.HasValue || userReview.PRODUCTID.Value == Guid.Empty) && (!userReview.SERVICEID.HasValue || userReview.SERVICEID.Value == Guid.Empty))
                    throw new ArgumentException("Both PRODUCTID SERVICEID can not be null together", "UserReview");

                if ((userReview.PRODUCTID.HasValue && userReview.PRODUCTID.Value != Guid.Empty) && (userReview.SERVICEID.HasValue && userReview.SERVICEID.Value != Guid.Empty))
                    throw new ArgumentException("Both PRODUCTID SERVICEID can not have values together", "UserReview");

                if(!userReview.REVIEWERID.HasValue || userReview.REVIEWERID.Value == Guid.Empty)
                    throw new ArgumentException("REVIEWERID can not be null", "UserReview");

                if (userReview.RATING == null && string.IsNullOrEmpty(userReview.COMMENTS))
                    return Guid.Empty;

                if (!userReview.ID.HasValue || userReview.ID.Value == Guid.Empty)
                    userReview.ID = Guid.NewGuid();
                userReview.REVIEWDATE = DateTime.Now;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.REVIEWS.Add(userReview);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }
                return userReview.ID.Value;
            }
            catch(Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Get user by email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public USER GetUserById(String email,String password)
        {
            try
            {
                if (email.Equals("")||email==null)
                    throw new ArgumentNullException("EMAIL", "EMAIL ID can not be null");

                USER user;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        user = (from p in db.USERS
                                where p.EMAILID == email && p.PASSWORD == password
                                select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        user = null;    // user not availble 
                    }
                    catch (InvalidOperationException e)
                    {
                        user = null;    // multiple users available with same id
                    }
                }

                return user;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Edit buyer/ seller profile details
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool EditUserDetails(USER user)
        {
            try
            {
                if (user == null)
                    throw new ArgumentNullException("User", "User can not be null");

                if (user.ID == null)
                    throw new ArgumentNullException("User", "User ID can not be null");                             

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        USER existingUser = (from u in db.USERS
                                             where u.ID == user.ID
                                             select u).Single();

                        if (user.ROLEID != null && existingUser.ROLEID != user.ROLEID)
                            throw new ArgumentException("ROLEID can not be changed using this EditUserDetails service");
                        if(user.USERNAME != null && existingUser.USERNAME != user.USERNAME)
                            throw new ArgumentException("USERNAME can never be modified");

                        if (user.NAME != null) existingUser.NAME = user.NAME;
                        if (user.PASSWORD != null) existingUser.PASSWORD = user.PASSWORD;
                        if (user.CONTACTNUMBER != null) existingUser.CONTACTNUMBER = user.CONTACTNUMBER;
                        if (user.EMAILID != null) existingUser.EMAILID = user.EMAILID;
                        if (user.PLACE != null) existingUser.PLACE = user.PLACE;
                        if (user.CITY != null) existingUser.CITY = user.CITY;
                        if (user.STATE != null) existingUser.STATE = user.STATE;
                        if (user.PINCODE != null) existingUser.PINCODE = user.PINCODE;

                        db.SaveChanges();
                        return true;
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }                
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Get product by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PRODUCT GetProductById(Guid? id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                    throw new ArgumentNullException("ID", "ID can not be null");

                PRODUCT product; 

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        product = (from p in db.PRODUCTS
                                 where p.ID == id
                                 select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch(ArgumentNullException e)
                    {
                        product = null; // no such product
                    }
                    catch(InvalidOperationException e)
                    {
                        product = null; // multiple products with same id
                    }
                }
                return product;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Add new product to Cart
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Guid AddServiceInOrder(SERVICEORDER product)
        {
            try
            {

                if (product == null)
                    throw new ArgumentNullException("Service", "Service can not be null");

                // check if all required fields are present
                if ((product.SERVICEID == null || product.SERVICEID == Guid.Empty) ||
                    (product.BUYERID == null || product.BUYERID == Guid.Empty))
                    throw new ArgumentException("Some mandatory parameters required to add a new product are missing", "Product");
                try
                {
                    using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                    {
                        try
                        {
                            db.SERVICEORDERs.Add(product);
                            db.SaveChanges();
                        }
                        catch (System.Data.DataException e)
                        {
                            throw new Exception(e.InnerException.InnerException.Message);
                        }
                    }
                    return product.SERVICEID;
                }
                catch (Exception e)
                {
                    throw new Exception(e.InnerException.InnerException.Message);
                }

            }
            catch (Exception e)
            {
                throw new Exception(e.InnerException.InnerException.Message);
            }



        }
Ejemplo n.º 44
0
        /// <summary>
        /// Get all product orders for a user
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List<ORDER> GetAllProductOrdersById(Guid? categoryId)
        {
            try
            {
                if (!categoryId.HasValue || categoryId.Value == Guid.Empty)
                    throw new ArgumentNullException("CategoryId", "CategoryId can not be null");

                List<ORDER> products = new List<ORDER>();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        products = (from p in db.ORDERS
                                    where p.BUYERID == categoryId && p.ISACTIVE == true && p.ISSERVICE == false
                                    select p).ToList();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                    }
                }
                return products;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Get service by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SERVICE GetServiceById(Guid? id)
        {
            try
            {
                if (!id.HasValue || id.Value == Guid.Empty)
                    throw new ArgumentNullException("ID", "ID can not be null");

                SERVICE service;

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        service = (from p in db.SERVICES
                                 where p.ID == id
                                 select p).Single();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                    catch (ArgumentNullException e)
                    {
                        service = null; // no such service
                    }
                    catch(InvalidOperationException e)
                    {
                        service = null;
                    }
                }
                return service;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Add new Seller/ Buyer
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Guid AddNewUser(USER user)
        {
            try
            {
                if (user == null)
                    throw new ArgumentNullException("User", "User can not be null");

                if(user.ROLEID == (int)UserRoles.Admin)
                    throw new ArgumentException("Admins can not be added using this service", "User");

                // check if all required fields are present
                if (user.USERNAME == null || user.PASSWORD == null || user.NAME == null || user.GENDER == null || user.CONTACTNUMBER == null)
                    throw new ArgumentException("Some mandatory parameters required to add a new user are missing", "User");

                // by default, all users are buyers
                if (!user.ROLEID.HasValue) user.ROLEID = (int)UserRoles.Buyer;

                // check if all additional required fields for seller are present
                if (user.ROLEID == (int)UserRoles.Seller && 
                    (user.EMAILID == null || user.PLACE == null || user.CITY == null || user.STATE == null || user.PINCODE == null))
                    throw new ArgumentException("Some additional mandatory parameters required to add a new seller are missing", "User");

                if (!user.ID.HasValue || user.ID.Value == Guid.Empty)
                    user.ID = Guid.NewGuid();

               //  user.ROLE.ROLENAME = "BUYER";

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.USERS.Add(user);
                        db.SaveChanges();
                    }

                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}",
                                                        validationError.PropertyName,
                                                        validationError.ErrorMessage);
                            }
                        }
                    }

                    catch(System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }              
                }
                    
                return user.ID.Value;
            }
            catch(Exception e)
            {
                throw;
            }
        }