示例#1
0
        public void DeleteOrganizationProduct(int organizationProductID, bool bypass = true)
        {
            if (!UserSession.CurrentUser.IsSystemAdmin && bypass)
            {
                return;
            }
            try
            {
                OrganizationProducts organizationProducts = new OrganizationProducts(UserSession.LoginUser);
                organizationProducts.LoadByOrganizationProductID(organizationProductID);
                UserProducts userProducts = new UserProducts(UserSession.LoginUser);
                //userProducts.LoadByOrganizationProductAndVersionID(organizationProducts[0].OrganizationID, "hola", "adios");
                userProducts.LoadByOrganizationProductAndVersionID(organizationProducts[0].OrganizationID, organizationProducts[0].ProductID, organizationProducts[0].ProductVersionID);
                userProducts.DeleteAll();
                userProducts.Save();
                organizationProducts.DeleteFromDB(organizationProductID);

                Product p           = Products.GetProduct(TSAuthentication.GetLoginUser(), organizationProducts[0].ProductID);
                string  description = String.Format("{0} deleted product association to {1} ", TSAuthentication.GetUser(TSAuthentication.GetLoginUser()).FirstLastName, p.Name);
                ActionLogs.AddActionLog(TSAuthentication.GetLoginUser(), ActionLogType.Delete, ReferenceType.Organizations, organizationProducts[0].OrganizationID, description);
            }
            catch (Exception ex)
            {
                DataUtils.LogException(UserSession.LoginUser, ex);
            }
        }
示例#2
0
        public bool BuyProduct(string userId, int productId)
        {
            var user = this.DbContext
                       .Users
                       .FirstOrDefault(x => x.Id == userId);

            var product = this.DbContext
                          .Products
                          .FirstOrDefault(x => x.Id == productId);

            if (user == null || product == null)
            {
                return(false);
            }

            var userProduct = new UserProducts()
            {
                UserId    = userId,
                ProductId = productId,
                BoughtOn  = DateTime.UtcNow
            };

            bool alreadyInFavourites = this.DbContext.UserBoughtProducts
                                       .Any(x => x.UserId == userId && x.ProductId == productId);

            if (alreadyInFavourites)
            {
                return(false);
            }

            user.BoughtProducts.Add(userProduct);
            this.DbContext.SaveChanges();

            return(true);
        }
        // GET
        public ActionResult Index()
        {
            var model = new UserProducts();

            model.Users    = _userRepo.GetAll();
            model.Products = _productRepo.GetAll();
            return(View(model));
        }
示例#4
0
 public void Update(UserProducts userProducts)
 {
     using (IDbConnection db = new SqlConnection(connectionString))
     {
         var sqlQuery = "UPDATE UserProducts SET UserId = @UserId, ProductId = @ProductId WHERE Id = @Id";
         db.Execute(sqlQuery, userProducts);
     }
 }
示例#5
0
        public ActionResult RemoveFromFav(int id)
        {
            UserProducts userProd = db.UserProducts.Find(User.Identity.GetUserId(), id);

            db.UserProducts.Remove(userProd);
            db.SaveChanges();
            return(RedirectToAction("Show", "Products", new { id = id }));
        }
示例#6
0
 public void Create(UserProducts userProducts)
 {
     using (IDbConnection db = new SqlConnection(connectionString))
     {
         var sqlQuery = "INSERT INTO UserProducts (UserId, ProductId) VALUES(@UserId, @ProductId); SELECT CAST(SCOPE_IDENTITY() as int)";
         int?id       = db.Query <int>(sqlQuery, userProducts).FirstOrDefault();
         userProducts.Id = id ?? 0;
     }
 }
示例#7
0
        public void DeleteProduct(Guid idProduct, Guid idUser)
        {
            UserProducts userProduct = context.UserProducts.Where(x => x.IdProduct == idProduct && x.IdUser == idUser)
                                       .FirstOrDefault();

            context.UserProducts.Remove(userProduct);

            context.SaveChanges();
        }
        public void Update(DataContracts.UserProducts entity)
        {
            UserProducts up = _source.First(o => o.IdProduct == entity.IdProduct && o.IdUser == entity.IdUser);

            if (up != null)
            {
                up.Quantity = entity.Quantity;
            }
        }
        public static string GetUserProduct(RestCommand command, int userProductID)
        {
            UserProduct userProduct = UserProducts.GetUserProduct(command.LoginUser, userProductID);

            if (userProduct.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(userProduct.GetXml("UserProduct", true));
        }
示例#10
0
        public UserProducts Get(int id)
        {
            UserProducts userProducts = null;

            using (IDbConnection db = new SqlConnection(connectionString))
            {
                userProducts = db.Query <UserProducts>("SELECT * FROM UserProducts WHERE Id = @id", new { id }).FirstOrDefault();
            }

            return(userProducts);
        }
示例#11
0
        private void SaveProducts()
        {
            foreach (var prod in this.HandleDoublons())
            {
                UserProducts entity = new UserProducts();
                entity.IdProduct = prod.First.ID;
                entity.IdUser    = this.Context.ApplicationUser.ID;
                entity.Quantity  = prod.Second;

                UserProductsRepo.Insert(entity);
            }
        }
示例#12
0
 public void SaveProduct(UserProducts product)
 {
     if (product.Id == default)
     {
         context.Entry(product).State = EntityState.Added;// объект будет добавлен как новый
     }
     else
     {
         context.Entry(product).State = EntityState.Modified;// старый объект будет изменён
     }
     context.SaveChanges();
 }
示例#13
0
        public ActionResult FromCart(string id, string name, string amount)
        {
            if (id != null)
            {
                var str     = Request.Cookies["cart"].Value.ToString();
                var id_s    = id + "," + name + "," + amount;
                var replace = "";

                var res = Regex.Replace(str, id_s, replace);

                Response.Cookies["cart"].Value = res;

                var            c_ps = res.Split('|');
                List <Product> temp = new List <Product>();
                foreach (var i in c_ps)
                {
                    var p = i.Split(',');

                    if (p[0] != "")
                    {
                        int ii_int  = Convert.ToInt32(p[0]);
                        int amountt = Convert.ToInt32(p[2]);
                        var new_p   = new Product
                        {
                            Id     = ii_int,
                            Pname  = p[1],
                            Amount = amountt,
                            Status = 1
                        };
                        temp.Add(new_p);
                    }
                }

                UserProducts cart_pros = new UserProducts
                {
                    ProductsV = temp
                };
                if (cart_pros.ProductsV.Count > 0)
                {
                    return(PartialView("~/Views/Users/_Cart.cshtml", cart_pros));
                }
                else
                {
                    return(Content("You don't have any product in your cart at the time..."));
                }
            }
            else
            {
                TempData["Error"] = "Spmething went wrong ! Please try again... ";
                return(RedirectToAction("Index", "Products"));
            }
        }
        public static string GetUserProducts(RestCommand command)
        {
            UserProducts userProducts = new UserProducts(command.LoginUser);

            userProducts.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(userProducts.GetXml("UserProducts", "UserProduct", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
示例#15
0
        // GET: Users/Profile/5
        public ActionResult Profile(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            List <Product> temp = new List <Product>();

            if (Request.Cookies["cart"] != null)
            {
                var ps = Request.Cookies["cart"].Value.ToString().Split('|');
                foreach (var i in ps)
                {
                    if (i != "")
                    {
                        var p      = i.Split(',');
                        int i_int  = Convert.ToInt32(p[0]);
                        int amount = Convert.ToInt32(p[2]);
                        var new_p  = new Product
                        {
                            Id     = i_int,
                            Pname  = p[1],
                            Amount = amount,
                            Status = 1
                        };
                        temp.Add(new_p);
                    }
                }
            }
            else
            {
                temp = null;
            }

            UserProducts user = new UserProducts
            {
                UserV       = ent.Users.Find(id),
                ProductsV   = temp,
                Bought_Prod = ent.Sold_products.Where(x => x.U_id == id).ToList()
            };

            if (user.UserV == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
示例#16
0
 public void DeleteUserProduct(int userProductID)
 {
     if (!UserSession.CurrentUser.IsSystemAdmin)
     {
         return;
     }
     try
     {
         UserProducts userProducts = new UserProducts(UserSession.LoginUser);
         userProducts.DeleteFromDB(userProductID);
     }
     catch (Exception ex)
     {
         DataUtils.LogException(UserSession.LoginUser, ex);
     }
 }
示例#17
0
        private List <UserProducts> MapUSERPRODUCTS(IDataReader reader)
        {
            List <UserProducts> list = new List <UserProducts>();

            while (reader.Read())
            {
                UserProducts userproducts = new UserProducts()
                {
                    IdUser    = Tools.ChangeType <int>(reader["idUser"]),
                    IdProduct = Tools.ChangeType <int>(reader["idProduct"]),
                    Quantity  = Tools.ChangeType <int>(reader["quantity"]),
                };
                list.Add(userproducts);
            }
            return(list);
        }
示例#18
0
        public CloseOrderVM(ApplicationDbContext ctx, int orderID, ApplicationUser user)
        {
            DefaultShippingAddress = ctx.ShippingAddress.SingleOrDefault(sa => sa.User == user && sa.IsDefault == true);

            DefaultBillingAddress = ctx.BillingAddress.SingleOrDefault(ba => ba.User == user && ba.IsDefault == true);

            DefaultPaymentType = ctx.PaymentType.SingleOrDefault(pt => pt.User == user && pt.IsActive == true && pt.IsPrimary == true);

            User = user;

            Order = ctx.Order.SingleOrDefault(o => o.OrderID == orderID && o.User == user);

            UserProducts = ctx.CompositeProduct
                           .Include(cp => cp.ProductType)
                           .Include(cp => cp.Ink)
                           .Include(cp => cp.Screen)
                           .Where(cp => cp.OrderID == orderID);

            ShoppingCartTotal = UserProducts.Sum(cp => cp.Price);
        }
示例#19
0
        public ActionResult AddToFav(int id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            UserProducts userProd = new UserProducts();

            userProd.ProductId = id;
            userProd.UserId    = User.Identity.GetUserId();
            try
            {
                db.UserProducts.Add(userProd);
                db.SaveChanges();

                return(RedirectToAction("Show", "Products", new { id = id }));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Show", "Products", new { id = id }));
            }
        }
示例#20
0
        // GET: Sold
        public ActionResult Buy(string p_id, string amount)
        {
            if (Session["u_id"] != null)
            {
                int id    = Convert.ToInt32(p_id);
                int a_int = Convert.ToInt32(amount);
                if (id != 0)
                {
                    var prod  = ent.Products.FirstOrDefault(x => x.Id == id);
                    int i_int = (int)Session["u_id"];

                    Sold_products product = new Sold_products
                    {
                        P_id   = prod.Id,
                        U_id   = i_int,
                        C_id   = (int)prod.Cid,
                        Date   = DateTime.UtcNow,
                        P_name = prod.Pname
                    };
                    ent.Sold_products.Add(product);
                    var flag = ent.SaveChanges();
                    prod.Amount           = prod.Amount - a_int;
                    ent.Entry(prod).State = System.Data.Entity.EntityState.Modified;
                    ent.SaveChanges();

                    //Fromcart(prod.Id, prod.Pname, prod.Amount + a_int);
                    var str     = Request.Cookies["cart"].Value.ToString();
                    var id_s    = prod.Id.ToString() + "," + prod.Pname + "," + (prod.Amount + a_int).ToString();
                    var replace = "";

                    var res = Regex.Replace(str, id_s, replace);
                    Response.Cookies["cart"].Value = res;

                    //var c_ps = Request.Cookies["cart"].Value.ToString().Split('|');
                    var            c_ps = res.Split('|');
                    List <Product> temp = new List <Product>();
                    foreach (var i in c_ps)
                    {
                        var p = i.Split(',');

                        if (p[0] != "")
                        {
                            int ii_int  = Convert.ToInt32(p[0]);
                            int amountt = Convert.ToInt32(p[2]);
                            var new_p   = new Product
                            {
                                Id     = ii_int,
                                Pname  = p[1],
                                Amount = amountt,
                                Status = 1
                            };
                            temp.Add(new_p);
                        }
                    }

                    UserProducts cart_pros = new UserProducts
                    {
                        ProductsV = temp
                    };
                    if (cart_pros.ProductsV.Count > 0)
                    {
                        return(PartialView("~/Views/Users/_Cart.cshtml", cart_pros));
                    }
                    else
                    {
                        return(Content("You don't have any product in your cart at the time..."));
                    }
                }
                else
                {
                    TempData["Error"] = "There was an error, please try again...";
                    return(RedirectToAction("Profile", "Users", new { id = (int)Session["u_id"] }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Account"));
            }
        }
        public static List <UserProducts> GetProductsOfUser(int UserId)
        {
            List <Tuple <int, int> > productIDs = new List <Tuple <int, int> >();

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

            try
            {
                connection.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    cmd.CommandText = "SELECT * FROM user_products WHERE user_id = @ID";
                    cmd.Parameters.AddWithValue("@ID", UserId);

                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productIDs.Add(new Tuple <int, int>(reader.GetInt32(1), reader.GetInt32(2)));
                        }
                    }
                }

                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    User tempUser = UserController.GetUserById(UserId);
                    cmd.CommandText = "SELECT * FROM products WHERE productid = @ProductId";

                    productIDs.ForEach(productamount =>
                    {
                        cmd.Parameters.AddWithValue("@ProductId", productamount.Item1);

                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Product tempProduct   = new Product();
                                tempProduct.ProductID = reader.GetInt32(0);
                                tempProduct.Name      = reader.GetString(1);
                                tempProduct.Price     = reader.GetFloat(2);

                                UserProducts tempUserProducts = new UserProducts();
                                tempUserProducts.User         = tempUser;
                                tempUserProducts.Product      = tempProduct;
                                tempUserProducts.Amount       = productamount.Item2;

                                products.Add(tempUserProducts);
                            }
                        }
                    });
                }
                connection.Close();
            }
            catch (SQLiteException e)
            {
                connection.Close();
                Debug.WriteLine(e);
                return(null);
            }
            return(products);
        }
        public ResponseModel AddProduct(AddProductModel addProduct)
        {
            ResponseModel result = new ResponseModel();

            result = ValidateAddProduct(addProduct);

            if (!result.IsSuccess)
            {
                return(result);
            }

            using (var t = new TransactionScope())
            {
                try
                {
                    UserProducts new_p = new UserProducts();
                    new_p.UserID      = addProduct.UserID;
                    new_p.CreateDate  = DateTime.Now;
                    new_p.Description = addProduct.Description;
                    new_p.IsPublish   = addProduct.IsPublish;
                    new_p.Keywords    = addProduct.Keywords;
                    new_p.Price       = addProduct.Price;
                    new_p.Tags        = addProduct.Tags;
                    new_p.Name        = addProduct.Name;
                    new_p.Uri         = new PostManager().GenerateUriFormat(addProduct.Uri);
                    new_p.ID          = _proRepo.Insert(new_p);

                    if (addProduct.MainImage != null)
                    {
                        string file_name = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
                        string baseMap   = Path.Combine(addProduct.BasePhotoPath, file_name);
                        _imM.SaveProductImage(addProduct.MainImage, baseMap);
                        ProductPhotos mainPhoto = new ProductPhotos();
                        mainPhoto.IsMain    = true;
                        mainPhoto.Photo     = file_name;
                        mainPhoto.ProductID = new_p.ID;
                        _photoRepo.Insert(mainPhoto);
                    }

                    if (addProduct.Photos != null)
                    {
                        foreach (var item in addProduct.Photos)
                        {
                            string file_name = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
                            string baseMap   = Path.Combine(addProduct.BasePhotoPath, file_name);
                            _imM.SavePostMainPage(item, baseMap);
                            ProductPhotos mainPhoto = new ProductPhotos();
                            mainPhoto.IsMain    = false;
                            mainPhoto.Photo     = file_name;
                            mainPhoto.ProductID = new_p.ID;
                            _photoRepo.Insert(mainPhoto);
                        }
                    }
                    result.Message   = "Ürün başarı ile eklendi!";
                    result.IsSuccess = true;
                    t.Complete();
                }
                catch (Exception ex)
                {
                    result.IsSuccess = false;
                    result.Message   = ex.Message;
                    t.Dispose();
                }
            }

            return(result);
        }