Пример #1
0
 public ActionResult Create(Manufacturer_CreateViewmodel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (string.IsNullOrEmpty(model.name))
             {
                 model.name = "";
             }
             if (string.IsNullOrEmpty(model.image))
             {
                 model.image = "no_image.png";
             }
             db.oc_manufacturer.Add(new oc_manufacturer()
             {
                 image      = model.image,
                 name       = model.name,
                 sort_order = model.sort_order,
                 status     = 1,
             });
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #2
0
 protected override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     base.OnActionExecuted(filterContext);
     if (User.Identity.IsAuthenticated)
     {
         if (!db.oc_customer_online.Any(r => r.ip == Request.UserHostAddress))
         {
             db.oc_customer_online.Add(new oc_customer_online
             {
                 ip          = Request.UserHostAddress,
                 date_added  = DateTime.Now,
                 referer     = Request.UrlReferrer.ToString() ?? "",
                 url         = Request.Url.ToString(),
                 customer_id = db.oc_customer.Where(r => r.email == User.Identity.Name).Single().customer_id
             });
         }
         else
         {
             var record = db.oc_customer_online.Where(r => r.ip == Request.UserHostAddress).Single();
             record.referer = Request.UrlReferrer == null ? "" : Request.UrlReferrer.ToString();
             record.url     = Request.Url.ToString();
         }
         db.SaveChanges();
     }
 }
Пример #3
0
        public ActionResult Register(string username, string password)
        {
            var hash_bytes    = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(password));
            var password_hash = string.Concat(hash_bytes.Select(b => b.ToString("x2")));

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                try
                {
                    MailAddress m = new MailAddress(username);
                }
                catch (Exception)
                {
                    ViewBag.Error = "Email không hợp lệ";
                    return(View());
                }
                ViewBag.Error = "email hoặc mật khẩu không hợp lệ";
                return(View());
            }
            if (db.oc_customer.Any(r => r.email == username))
            {
                ViewBag.Error = "Email đã tồn tại";
                return(View());
            }

            db.oc_customer.Add(new oc_customer()
            {
                email             = username,
                password          = password_hash,
                customer_group_id = 1, // mặc định,
                firstname         = "tên",
                lastname          = "họ",
                status            = 1,
                address_id        = 0, // không có;
                date_added        = DateTime.Now,
                custom_field      = "",
                cart        = "",
                code        = "",
                fax         = "",
                ip          = "",
                token       = "",
                safe        = 1,
                newsletter  = 0,
                salt        = "",
                language_id = 1,
                store_id    = 1,
                telephone   = "sđt",
                wishlist    = "",
            });
            db.SaveChanges();
            FormsAuthentication.SetAuthCookie(username, true);
            return(RedirectToAction("Index", "Home"));
        }
Пример #4
0
        public JsonResult add_more_minor_image(int product_id)
        {
            var created = db.oc_product_image.Add(new oc_product_image()
            {
                image      = "no_image.png",
                product_id = product_id,
                sort_order = 0,
            });

            db.SaveChanges();
            return(Json(new { m = "ok", created = created.product_image_id }));
        }