Esempio n. 1
0
        public bool UpdatePromo(string code, string idusercookie)
        {
            bool result = false;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var registro = db.PromoCodeUsed.Where(s => s.idUser == idusercookie && s.Used == false).FirstOrDefault();
                    if (registro != null)
                    {
                        registro.PromoCode       = code;
                        db.Entry(registro).State = EntityState.Modified;
                        db.SaveChanges();

                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        public bool UpdateRoleUser(string email)
        {
            bool result = false;

            try
            {
                using (dekkOnlineEntities db = new dekkOnlineEntities())
                {
                    var useremail = db.AspNetUsers.Where(s => s.Email == email).FirstOrDefault();
                    if (useremail != null)
                    {
                        useremail.Roles           = 1;
                        useremail.Active          = true;
                        db.Entry(useremail).State = EntityState.Modified;
                        db.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 3
0
        public bool updateDeleveryType(string IdUser1, string idUserCookies)
        {
            bool result = false;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var registro = db.DeliveryType.Where(s => s.IdUser == idUserCookies).OrderByDescending(s => s.IdUser).FirstOrDefault();
                    if (registro != null)
                    {
                        registro.IdUser          = IdUser1;
                        db.Entry(registro).State = EntityState.Modified;
                        db.SaveChanges();

                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
            }
            return(result);
        }
Esempio n. 4
0
 //DELETE FROM CART DE-11 TASK 5
 public bool DeleteProductFromCart(string idcart, string idUser)
 {
     Framework.encryptdecrypt en = new encryptdecrypt();
     try
     {
         int id = Convert.ToInt32(en.DesEncriptar(idcart));
         using (var db = new dekkOnlineEntities())
         {
             var addCart = new ShoppingCart();
             var d       = db.ShoppingCart.Where(x => x.Id == id).FirstOrDefault();
             if (d != null)
             {
                 var promocodeused = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault();
                 if (promocodeused != null)
                 {
                     var percent = db.PromotionCode.Where(s => s.IdCode == promocodeused.PromoCode).Select(s => s.PercentCode).FirstOrDefault();
                     percent = percent / 100;
                     promocodeused.TotalPrice      = promocodeused.TotalPrice - d.Price;
                     promocodeused.TotalPriceFinal = promocodeused.TotalPrice - (percent * (promocodeused.TotalPrice));
                     db.Entry(promocodeused).State = EntityState.Modified;
                 }
                 db.ShoppingCart.Remove(d);
                 db.SaveChanges();
                 var user = db.ShoppingCart.Where(s => s.IdUser == idUser && s.Status == false).FirstOrDefault();
                 if (user != null)
                 {
                     return(true);
                 }
                 else if (user == null)
                 {
                     var promocodeused2 = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault();
                     if (promocodeused2 != null)
                     {
                         db.PromoCodeUsed.Remove(promocodeused2);
                         db.SaveChanges();
                         return(true);
                     }
                     else
                     {
                         return(true);
                     }
                 }
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         //_Error = ex;
         return(false);
     }
 }
Esempio n. 5
0
        public bool UpdateDataUser(string zipcore, string name, string lastname, string address, string email, string mobile, string idUser1)
        {
            bool result = false;

            try
            {
                using (dekkOnlineEntities db = new dekkOnlineEntities())
                {
                    var userdata  = db.UserAddress.Where(s => s.IdUser == idUser1).FirstOrDefault();
                    var useremail = db.AspNetUsers.Where(s => s.Id == idUser1).FirstOrDefault();
                    if (userdata == null && useremail != null)
                    {
                        UserAddress us = new UserAddress();
                        us.IdUser    = idUser1;
                        us.FirstName = name;
                        us.LastName  = lastname;
                        us.Address   = address;
                        us.Phone     = mobile;
                        us.ZipCode   = Convert.ToInt32(zipcore);
                        //us.WorkShopManager = false;
                        //useremail.Email = email;
                        //useremail.UserName = email;
                        //db.Entry(useremail).State = EntityState.Modified;
                        db.UserAddress.Add(us);
                        db.SaveChanges();
                        result = true;
                    }
                    else if (userdata != null && useremail != null)
                    {
                        userdata.FirstName = name;
                        userdata.LastName  = lastname;
                        userdata.Address   = address;
                        userdata.Phone     = mobile;
                        userdata.ZipCode   = Convert.ToInt32(zipcore);
                        //userdata.WorkShopManager = false;
                        //useremail.Email = email;
                        //useremail.UserName = email;
                        db.Entry(userdata).State = EntityState.Modified;
                        //db.Entry(useremail).State = EntityState.Modified;
                        db.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 6
0
        //DE-14 2
        public bool updateAddressUser(string idUser, string firstName, string lastName, string address, string phone, int zipCode, string latitude, string length)
        {
            bool Result = false;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var result = db.UserAddress.Where(s => s.IdUser == idUser).FirstOrDefault();
                    if (result != null)
                    {
                        result.FirstName = firstName;
                        result.LastName  = lastName;
                        result.Address   = address;
                        result.Phone     = phone;
                        result.ZipCode   = zipCode;
                        result.Latitude  = latitude;
                        result.Length    = length;
                        //result.WorkShopManager = false;
                        db.Entry(result).State = EntityState.Modified;
                        db.SaveChanges();
                        Result = true;
                    }
                    else if (result == null)
                    {
                        UserAddress us = new UserAddress();
                        us.FirstName = firstName;
                        us.LastName  = lastName;
                        us.Address   = address;
                        us.Phone     = phone;
                        us.ZipCode   = zipCode;
                        us.Latitude  = latitude;
                        us.Length    = length;
                        db.UserAddress.Add(us);
                        db.SaveChanges();
                        Result = true;
                    }
                    else
                    {
                        Result = false;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Result);
        }
Esempio n. 7
0
        //LOAD CURRENT POINTS PER USER DE-11 TASK 3
        public int LoadPointsPerUser(string idUser)
        {
            var NowPointsLoad = (dynamic)null;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var user = db.AspNetUsers.Where(s => s.Id == idUser).FirstOrDefault();
                    if (user != null)
                    {
                        NowPointsLoad = db.DetailUserPoints.Where(s => s.IdUser == idUser && s.StatusofPromo == true).Select(s => s.PointsEarned).Sum().ToString();

                        if (NowPointsLoad == null || NowPointsLoad == "")
                        {
                            NowPointsLoad = "0";
                        }

                        var UserPoints = db.UserPoints.Where(s => s.IdUser == idUser).FirstOrDefault();
                        if (UserPoints == null)
                        {
                            var points = new Entity.UserPoints();

                            points.IdUser = idUser;
                            points.Points = Convert.ToInt32(NowPointsLoad);
                            db.UserPoints.Add(points);
                            db.SaveChanges();
                            return(Convert.ToInt32(NowPointsLoad));
                        }
                        else
                        {
                            UserPoints.Points          = Convert.ToInt32(NowPointsLoad);
                            db.Entry(UserPoints).State = EntityState.Modified;
                            db.SaveChanges();
                            return(Convert.ToInt32(NowPointsLoad));
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 8
0
        //DE-14 5
        public bool addToUserAddress(string idUser, string firstName, string lastName, string address, string phone, int zipCode, string latitude, string length)
        {
            bool result = false;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var user = db.UserAddress.Where(s => s.IdUser == idUser).FirstOrDefault();
                    if (user == null)
                    {
                        var addUserAddress = new Entity.UserAddress();
                        addUserAddress.IdUser    = idUser;
                        addUserAddress.FirstName = firstName;
                        addUserAddress.LastName  = lastName;
                        addUserAddress.Address   = address;
                        addUserAddress.Phone     = phone;
                        addUserAddress.ZipCode   = zipCode;
                        addUserAddress.Latitude  = latitude;
                        addUserAddress.Length    = length;
                        //addUserAddress.WorkShopManager = false;
                        db.UserAddress.Add(addUserAddress);
                        db.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        user.FirstName = firstName;
                        user.LastName  = lastName;
                        user.Address   = address;
                        user.Phone     = phone;
                        user.ZipCode   = zipCode;
                        user.Latitude  = latitude;
                        user.Length    = length;
                        //user.WorkShopManager = false;
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
Esempio n. 9
0
        //ADD TO CART DE-5 TASK 3
        public bool AddToCart(string idUser, int id_dekk, int id_quantity)
        {
            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    var                 productPrice        = db.products.Where(s => s.proId == id_dekk).Select(x => x.proSuggestedPrice).FirstOrDefault();
                    decimal             price               = Convert.ToDecimal(productPrice) * id_quantity;
                    var                 promocodeused       = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault();
                    Entity.ShoppingCart productShoppingCart = db.ShoppingCart.Where(s => s.proId == id_dekk && s.IdUser.Equals(idUser) && s.Status == false).FirstOrDefault();
                    price = (int)Math.Floor(price);
                    if (productShoppingCart == null)
                    {
                        Entity.ShoppingCart addCart = new Entity.ShoppingCart();
                        addCart.IdUser   = idUser;
                        addCart.proId    = id_dekk;
                        addCart.quantity = id_quantity;
                        addCart.Price    = price;
                        addCart.Status   = false;
                        db.ShoppingCart.Add(addCart);
                    }
                    else
                    {
                        productShoppingCart.quantity = id_quantity;
                        productShoppingCart.Price    = price;
                    }
                    if (promocodeused != null)
                    {
                        var percent = db.PromotionCode.Where(s => s.IdCode == promocodeused.PromoCode).Select(s => s.PercentCode).FirstOrDefault();
                        percent = percent / 100;
                        promocodeused.TotalPrice      = promocodeused.TotalPrice + price;
                        promocodeused.TotalPriceFinal = promocodeused.TotalPrice - (percent * (promocodeused.TotalPrice));
                        db.Entry(promocodeused).State = EntityState.Modified;
                    }

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //_Error = ex;
                return(false);
            }
        }
Esempio n. 10
0
 public string UpdateUserImage(string path, string idUser1)
 {
     try
     {
         using (var db = new dekkOnlineEntities())
         {
             var UserInfo = db.UserAddress.Where(s => s.IdUser == idUser1).FirstOrDefault();
             if (UserInfo != null)
             {
                 UserInfo.Image           = path;
                 db.Entry(UserInfo).State = EntityState.Modified;
                 db.SaveChanges();
                 var image = db.UserAddress.Where(s => s.IdUser == idUser1).Select(s => s.Image).FirstOrDefault();
                 return(image);
             }
             else if (UserInfo == null)
             {
                 UserAddress us2 = new UserAddress();
                 us2.IdUser = idUser1;
                 us2.Image  = path;
                 db.UserAddress.Add(us2);
                 db.SaveChanges();
                 var image = db.UserAddress.Where(s => s.IdUser == idUser1).Select(s => s.Image).FirstOrDefault();
                 return(image);
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Esempio n. 11
0
        //LOAD PROMO CODE FROM USER DE-11 TASK 2 cambios
        //public string LoadPromoCodeFomUser(string idUser)
        //{
        //    var promocode = (dynamic)null;
        //    try
        //    {
        //        using (var db = new dekkOnlineEntities())
        //        {
        //            promocode = db.PromotionCodeUser.Where(s => s.IdUser == idUser).Select(s => s.IdCode).FirstOrDefault();
        //            if (promocode != null)
        //            {
        //                return promocode;
        //            }
        //            else
        //            {
        //                return promocode = "";
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //        throw;
        //    }

        //}


        //VALIDATE PROMO CODE DE-11 cambios
        public bool ValidatePromoCode(string code, string idUser)
        {
            var    ivapor            = System.Configuration.ConfigurationManager.AppSettings["ivapre"];
            int    ivpre             = Convert.ToInt32(ivapor);
            double ivapor2           = Convert.ToDouble((double)ivpre / 100);
            var    promocodediscount = (dynamic)null;
            List <ResultShoppingCartProduct> products = null;

            try
            {
                using (var db = new dekkOnlineEntities())
                {
                    DateTime DateToday = DateTime.Now;
                    promocodediscount = db.PromotionCode.Where(p => p.IdCode == code && p.DateStart <= DateToday && p.DateEnd >= DateToday).Select(p => p.PercentCode).FirstOrDefault();
                    var promocodeuservalidate = db.PromotionCode.Where(p => p.IdUser == idUser && p.IdCode == code).FirstOrDefault();
                    if (promocodediscount != null && promocodeuservalidate == null)
                    {
                        var usercode        = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.PromoCode == code && s.Used == true).FirstOrDefault();
                        var usercodenotused = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false && s.PromoCode == code).FirstOrDefault();//aqui
                        if (usercode != null)
                        {
                            return(false);
                        }
                        else if (usercodenotused != null)
                        {
                            products = (from pro in db.products
                                        join cart in db.ShoppingCart on pro.proId equals cart.proId
                                        where cart.IdUser.Equals(idUser) && cart.Status == false
                                        select new ResultShoppingCartProduct
                            {
                                totalpriceprod = Math.Round((double)cart.Price, 2),
                            }).ToList();
                            double?totalprice = products.Select(p => p.totalpriceprod).Sum();
                            totalprice = (int)Math.Floor((decimal)totalprice);
                            double?totalprice2 = products.Select(p => p.totalpriceprod).Sum();
                            promocodediscount = promocodediscount / 100;
                            decimal totalpricepromocode = promocodediscount * (decimal)totalprice;
                            totalpricepromocode = (int)Math.Floor((decimal)totalpricepromocode);
                            totalprice          = totalprice - (double)totalpricepromocode;
                            //var iva = totalprice * ivapor2;//TAX
                            //totalprice = totalprice + iva; //Con esto comentado solo guardara el precio final de la orden sin el iva
                            totalprice = (int)Math.Floor((decimal)totalprice);
                            //totalprice2 = totalprice2 + iva;//Aqui guardara el precio de la orden sin validar el codigo de promocion y sin iva
                            usercodenotused.PromoCode       = code;
                            usercodenotused.TotalPrice      = (decimal)totalprice2;
                            usercodenotused.TotalPriceFinal = (decimal)totalprice;
                            usercodenotused.Used            = false;
                            usercodenotused.DateUsed        = DateTime.Now;
                            db.Entry(usercodenotused).State = EntityState.Modified;
                            db.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            products = (from pro in db.products
                                        join cart in db.ShoppingCart on pro.proId equals cart.proId
                                        where cart.IdUser.Equals(idUser) && cart.Status == false
                                        select new ResultShoppingCartProduct
                            {
                                totalpriceprod = Math.Round((double)cart.Price, 2),
                            }).ToList();
                            double?totalprice = products.Select(p => p.totalpriceprod).Sum();
                            totalprice = (int)Math.Floor((decimal)totalprice);
                            double?totalprice2 = products.Select(p => p.totalpriceprod).Sum();
                            promocodediscount = promocodediscount / 100;
                            decimal totalpricepromocode = promocodediscount * (decimal)totalprice;
                            totalpricepromocode = (int)Math.Floor((decimal)totalpricepromocode);
                            totalprice          = totalprice - (double)totalpricepromocode;
                            //var iva = totalprice * ivapor2;//TAX
                            //totalprice = totalprice + iva; //Con esto comentado solo guardara el precio final de la orden sin el iva
                            totalprice = (int)Math.Floor((decimal)totalprice);
                            //totalprice2 = totalprice2 + iva;//Aqui guardara el precio de la orden sin validar el codigo de promocion y sin iva
                            Entity.PromoCodeUsed addpromo = new Entity.PromoCodeUsed();
                            addpromo.idUser          = idUser;
                            addpromo.PromoCode       = code;
                            addpromo.TotalPrice      = (decimal)totalprice2;
                            addpromo.TotalPriceFinal = (decimal)totalprice;
                            addpromo.Used            = false;
                            addpromo.DateUsed        = DateTime.Now;
                            addpromo.Points          = 0;
                            db.PromoCodeUsed.Add(addpromo);
                            db.SaveChanges();
                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 12
0
 public string IncreaseProductFromCart(string idcart, int qty, string idUser)
 {
     Framework.encryptdecrypt en = new encryptdecrypt();
     try
     {
         int id = Convert.ToInt32(en.DesEncriptar(idcart));
         using (var db = new dekkOnlineEntities())
         {
             var d = db.ShoppingCart.Where(x => x.Id == id).FirstOrDefault();
             //var e = db.products.Where(x => x.proId == d.proId).FirstOrDefault();
             //if (e.proInventory > qty)
             //{
             //    if (d != null)
             //    {
             //        d.Price = ((d.Price / d.quantity) * qty);
             //        d.quantity = qty;
             //        db.SaveChanges();
             //        return true;
             //    }
             //    else
             //    {
             //        return false;
             //    }
             //}
             //else
             //{
             //    if (d != null)
             //    {
             //        d.Price = ((d.Price / d.quantity) * e.proInventory);
             //        d.quantity = e.proInventory;
             //        db.SaveChanges();
             //        return true;
             //    }
             //    else
             //    {
             //        return false;
             //    }
             //}
             if (d != null)
             {
                 var final = ((d.Price / d.quantity) * qty);
                 d.Price    = final;
                 d.quantity = qty;
                 var promocodeused = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault();
                 if (promocodeused != null)
                 {
                     var percent = db.PromotionCode.Where(s => s.IdCode == promocodeused.PromoCode).Select(s => s.PercentCode).FirstOrDefault();
                     percent = percent / 100;
                     promocodeused.TotalPrice      = promocodeused.TotalPrice + (final - promocodeused.TotalPrice);
                     promocodeused.TotalPriceFinal = promocodeused.TotalPrice - (percent * (promocodeused.TotalPrice));
                     db.Entry(promocodeused).State = EntityState.Modified;
                     db.Entry(d).State             = EntityState.Modified;
                 }
                 db.SaveChanges();
                 var qtyfinal = db.ShoppingCart.Where(s => s.Id == id).Select(s => s.Price).FirstOrDefault();
                 qtyfinal = (decimal)Math.Truncate((double)qtyfinal);
                 return(qtyfinal.ToString());
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }