예제 #1
0
        public async Task <ActionResult> Suggestion(Suggestion _sug)
        {
            if (_sug.Id == 0)
            {
                _sug.dateinsert  = DateTime.Now;
                _sug.statedelete = false;
                db.Suggestion.Add(_sug);
                await db.SaveChangesAsync();

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
            else
            {
                Suggestion _edsug = db.Suggestion.Find(_sug.Id);
                _edsug.dateinsert    = DateTime.Now;
                _edsug.statedelete   = false;
                _edsug.Name          = _sug.Name;
                _edsug.Email         = _sug.Email;
                _edsug.Message       = _sug.Message;
                _edsug.respondmessag = _sug.respondmessag;
                _edsug.Subject       = _sug.Subject;
                _edsug.Tel           = _sug.Tel;
                await db.SaveChangesAsync();

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public async Task <ActionResult> checkdiscountcod(string dicode)
        {
            long cusid = 0;

            if (Request.Cookies.AllKeys.Contains("customerId"))
            {
                cusid = Convert.ToInt64(CreatHash.Decrypt(Request.Cookies["customerId"].Value));
                Customer customerinfo = db.Customer.Where(p => p.Id == cusid).FirstOrDefault();
            }
            else
            {
                return(new HttpStatusCodeResult(508));
            }

            discountcode _discountcode = db.discountcode.Where(p => p.dicountcode == dicode).FirstOrDefault();

            if (_discountcode == null)
            {
                return(new HttpStatusCodeResult(506));
            }



            DateTime dateend = _discountcode.dateende;
            DateTime datenow = DateTime.Now;


            if (datenow > dateend)
            {
                return(new HttpStatusCodeResult(507));
            }


            if (_discountcode.numberofuseg == 0 || _discountcode.numberofuseg == null)
            {
                _discountcode.numberofuseg = 1;
                _discountcode.customerid   = cusid;
                await db.SaveChangesAsync();

                List <CustomerProduct> customerProducts = db.CustomerProduct.Where(p => p.CustomerId == cusid && p.IdState == 1).ToList();

                foreach (var item in customerProducts)
                {
                    factor factor = db.factor.Where(p => p.factorcode == item.factorcod).FirstOrDefault();
                    factor.discountcode    = _discountcode.dicountcode;
                    factor.discountpercent = _discountcode.discountpersent;
                }
                await db.SaveChangesAsync();
            }
            else if (_discountcode.numberofuseg >= 1)
            {
                return(new HttpStatusCodeResult(509));
            }



            return(Json(_discountcode.discountpersent, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> deletecustomerproduct(CustomerProduct _deletecustomerproduct)
        {
            long cusid = 0;

            if (Request.Cookies.AllKeys.Contains("customerId"))
            {
                cusid = Convert.ToInt64(CreatHash.Decrypt(Request.Cookies["customerId"].Value));
                CustomerProduct customerProduct = db.CustomerProduct.Where(p => p.CustomerId == cusid && p.Id == _deletecustomerproduct.Id).FirstOrDefault();
                customerProduct.StateDelete         = true;
                customerProduct.DateDelete          = DateTime.Now;
                customerProduct.ResonOfCancelletion = _deletecustomerproduct.ResonOfCancelletion;
                await db.SaveChangesAsync();

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(new HttpStatusCodeResult(506));
            }
        }
예제 #4
0
        public async Task <ActionResult> mngcustomer(Customer _mcustomer, HttpPostedFileBase _file1)
        {
            string fileImagename = "";


            if (!Request.Cookies.AllKeys.Contains("customerId"))
            {
                var unqusername = db.Customer.Where(p => p.UserName == _mcustomer.UserName).Any();

                var unquemail = db.Customer.Where(p => p.Email == _mcustomer.Email).Any();

                if (unqusername == true || unquemail == true)
                {
                    return(new HttpStatusCodeResult(503));
                }

                var pass = CreatHash.HashPass(_mcustomer.Password);
                _mcustomer.Password = pass;

                _mcustomer.DateInsert  = DateTime.Now;
                _mcustomer.Statedelete = false;

                if (Request.Files != null && Request.Files.Count != 0)
                {
                    _file1 = Request.Files[0];
                    if (!_file1.ContentType.Contains("image/jpeg"))
                    {
                        return(new HttpStatusCodeResult(502));
                    }
                    var number = new Random();
                    fileImagename = number.Next(1, 999999999).ToString() + _file1.FileName;
                    var path = Path.Combine(Server.MapPath("~/Image/CustomerImage"), fileImagename);
                    _file1.SaveAs(path);
                    _mcustomer.userimage = fileImagename;
                }

                db.Customer.Add(_mcustomer);
                await db.SaveChangesAsync();

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
            else
            {
                long cusid = 0;
                cusid = Convert.ToInt64(CreatHash.Decrypt(Request.Cookies["customerId"].Value));
                Customer _edmcustomer = db.Customer.Find(cusid);
                if (_mcustomer.Address == "" || _mcustomer.Address == null ||
                    _mcustomer.Mobile == "" || _mcustomer.Mobile == null ||
                    _mcustomer.Tel == "" || _mcustomer.Tel == null)
                {
                    return(new HttpStatusCodeResult(505));
                }
                bool uniquemail    = db.Customer.Where(p => p.Email == _mcustomer.Email && p.Id != _edmcustomer.Id).Any();
                bool uniquusername = db.Customer.Where(p => p.UserName == _mcustomer.UserName && p.Id != _edmcustomer.Id).Any();

                if (uniquemail == true || uniquusername == true)
                {
                    return(new HttpStatusCodeResult(503));
                }
                _edmcustomer.Address     = _mcustomer.Address;
                _edmcustomer.CompanyName = _mcustomer.CompanyName;
                _edmcustomer.DateUpdate  = DateTime.Now;
                _edmcustomer.Email       = _mcustomer.Email;
                _edmcustomer.FullName    = _mcustomer.FullName;
                _edmcustomer.Mobile      = _mcustomer.Mobile;

                _edmcustomer.Statedelete = false;
                _edmcustomer.Tel         = _mcustomer.Tel;
                _edmcustomer.UserName    = _mcustomer.UserName;

                if (Request.Files != null && Request.Files.Count != 0)
                {
                    _file1 = Request.Files[0];
                    if (!_file1.ContentType.Contains("image/jpeg"))
                    {
                        return(new HttpStatusCodeResult(502));
                    }

                    if (_edmcustomer.userimage != null && _edmcustomer.userimage != "")
                    {
                        var oldimg = Path.Combine(Server.MapPath("~/Image/CustomerImage"), _edmcustomer.userimage);
                        if (System.IO.File.Exists(oldimg))
                        {
                            System.IO.File.Delete(oldimg);
                        }
                    }
                    var number = new Random();
                    fileImagename = number.Next(1, 999999999).ToString() + _file1.FileName;
                    var path = Path.Combine(Server.MapPath("~/Image/CustomerImage"), fileImagename);
                    _file1.SaveAs(path);
                    _edmcustomer.userimage = fileImagename;
                }

                await db.SaveChangesAsync();

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
        }
예제 #5
0
        public async Task <ActionResult> registercustomerproduct(itemcart _prop, string discontcode, long?_toltalprice)
        {
            List <CustomerProduct> _customerproduct = new List <CustomerProduct>();
            CustomerProduct        _cp = null;
            long cusid = 0;

            if (Request.Cookies.AllKeys.Contains("customerId"))
            {
                cusid = Convert.ToInt64(CreatHash.Decrypt(Request.Cookies["customerId"].Value));
                Customer customerinfo = db.Customer.Where(p => p.Id == cusid).FirstOrDefault();
                if (customerinfo.Mobile == "" || customerinfo.Mobile == null || customerinfo.Address == "" || customerinfo.Address == null)
                {
                    return(new HttpStatusCodeResult(504));
                }
            }
            else
            {
                return(new HttpStatusCodeResult(501));
            }

            Random r = new Random();

            string factorcode = "";

            for (int i = 0; i < _prop.ListProps.Count(); i++)
            {
                long prid = _prop.ListProps[i].Id;

                #region deletecookie

                HttpCookie cookie = Request.Cookies["ProductBasketCookie"];
                cookie.Expires = DateTime.Now.AddDays(-11);

                Response.Cookies.Add(cookie);

                #endregion

                factorcode = _prop.ListProps[i].Id + r.Next(1, 999999999).ToString() + r.Next(1, 999999999).ToString();

                long _prices;

                var _price = db.ProductProperty.Where(p => p.IdProduct == prid && p.IdProperty == 4).FirstOrDefault().Value;
                _prices         = Convert.ToInt64(_price);
                _cp             = new CustomerProduct();
                _cp.Count       = _prop.ListProps[i].Value;
                _cp.CustomerId  = cusid;
                _cp.DateRequest = DateTime.Now;
                _cp.IdState     = 1;
                _cp.ProductId   = _prop.ListProps[i].Id;
                _cp.StateDelete = false;

                if (discontcode != null && discontcode != "")
                {
                    var discountpercent = db.discountcode.Where(p => p.dicountcode == discontcode).FirstOrDefault().discountpersent;

                    var totalprice = _prices - (_prices * discountpercent);

                    _cp.TotalPrice = _prop.ListProps[i].Value * totalprice;

                    _toltalprice  = 0;
                    _toltalprice += _cp.TotalPrice;
                }
                else
                {
                    _cp.TotalPrice = _prop.ListProps[i].Value * _prices;
                    _toltalprice   = 0;

                    _toltalprice += _cp.TotalPrice;
                }
                _cp.factorcod = factorcode;
                _customerproduct.Add(_cp);
            }
            factor _f = new factor();
            _f.customerId   = cusid;
            _f.dateinsert   = DateTime.Now;
            _f.discountcode = discontcode;
            if (discontcode != null && discontcode != "")
            {
                _f.discountpercent = db.discountcode.Where(p => p.dicountcode == discontcode).FirstOrDefault().discountpersent;
            }
            else
            {
                _f.discountpercent = null;
            }
            _f.factorcode  = factorcode;
            _f.prcount     = _customerproduct.Count();
            _f.statedelete = false;



            _f.totalprice = (long)_toltalprice;

            db.factor.Add(_f);
            db.CustomerProduct.AddRange(_customerproduct);
            await db.SaveChangesAsync();

            return(Json("ok", JsonRequestBehavior.AllowGet));
        }