Ejemplo n.º 1
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.º 2
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.º 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>
        /// 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.º 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>
        /// 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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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;
            }
        }