예제 #1
0
        public ActionResult ManageDelete(int id)
        {
            var p = dbt.items.FirstOrDefault(x => x.id == id);

            dbt.items.Remove(p);
            dbt.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult index(String name, String description, int quantity, int status, HttpPostedFileBase uploadImages)
        {
            using (vlutrading3545Entities db = new vlutrading3545Entities())
            {
                byte[] img           = null;
                string img_as_string = "";
                if (uploadImages != null)
                {
                    img = new byte[uploadImages.ContentLength];
                    using (BinaryReader read = new BinaryReader(uploadImages.InputStream))
                    {
                        img = read.ReadBytes(uploadImages.ContentLength);
                    }
                    img_as_string = Convert.ToBase64String(img);
                }
                item item = new item
                {
                    item_name   = name,
                    description = description,
                    quantity    = quantity,
                    status      = status,
                    images      = img_as_string,
                    seller_id   = 1,
                    create_by   = "vinh",
                    create_date = DateTime.Now,
                    update_by   = "vinh",
                    update_date = DateTime.Now
                };
                try
                {
                    db.items.Add(item);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewBag.DuplicateMessage = "Error occurred while create new item. Contact Admin for details";
                    return(View());

                    throw;
                }
                //if (uploadImages != null)
                //{
                //    string[] n = uploadImages.FileName.Split('.');
                //    string sfile = n[0] + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + n[1];
                //    string spath = Server.MapPath("~/Content/img/items/");
                //    string sfullpath = Path.Combine(spath, sfile);
                //    try
                //    {
                //        uploadImages.SaveAs(sfullpath);
                //        db.item_images.Add(new item_images
                //        {
                //            item_id = 1,
                //            filename = sfile,
                //            path = sfullpath,
                //            create_by = "vinh",
                //            create_date = DateTime.Now,
                //            update_by = "vinh",
                //            update_date = DateTime.Now
                //        });
                //        db.SaveChanges();
                //    }

                //    catch (Exception ex)
                //    {

                //    }


                //}
            }



            return(View());
        }
예제 #3
0
        public ActionResult register(USERMetadata newUser)
        {
            using (vlutrading3545Entities db = new vlutrading3545Entities())
            {
                var ques = db.security_question.ToList();
                List <SelectListItem> item = new List <SelectListItem>();
                foreach (var i in ques)
                {
                    item.Add(new SelectListItem
                    {
                        Text  = i.question,
                        Value = i.id.ToString()
                    });
                }

                ViewBag.question = item;

                if (ModelState.IsValid)
                {
                    if (db.users.Any(x => x.email == newUser.email))
                    {
                        ModelState.AddModelError("Email", "Email already exist");
                        return(View(newUser));
                    }
                    else if (db.users.Any(x => x.username == newUser.username))
                    {
                        ModelState.AddModelError("Username", "Username already exist");
                        return(View(newUser));
                    }
                    else
                    {
                        string ip_login = "";
                        if (Request.UserHostAddress != null)
                        {
                            ip_login = Request.UserHostAddress;
                        }
                        user usr = new user
                        {
                            username                 = newUser.username,
                            password                 = hashPwd(newUser.password),
                            email                    = newUser.email,
                            name                     = newUser.name,
                            role                     = 1,
                            id_security_question     = newUser.id_security_question,
                            answer_security_question = newUser.answer_security_question,
                            is_active                = 1,
                            ip_last_login            = ip_login,
                            last_login_date          = DateTime.Now,
                            create_by                = newUser.username,
                            create_date              = DateTime.Now,
                            update_by                = newUser.username,
                            update_date              = DateTime.Now
                        };
                        try
                        {
                            db.users.Add(usr);
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ViewBag.DuplicateMessage = "Error occurred while register. Contact Admin for details";
                            return(View());

                            throw;
                        }
                        ViewBag.SuccessMessage = "Successful Register";
                        ModelState.Clear();
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
        }