public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
示例#2
0
 public ActionResult AddComment(int id, Comment comment)
 {
     comment.ProductId = id;
     comment.UserId    = Convert.ToInt32(Session["userId"]);
     if (Session["userId"] == null)
     {
         return(RedirectToAction("Login", "User"));
     }
     comment.User    = db.Users.Find(comment.UserId);
     comment.Product = db.Products.Find(comment.ProductId);
     db.Comments.Add(comment);
     db.SaveChanges();
     return(RedirectToAction("Product", "Home", id));
 }
示例#3
0
 public static void Add(Custom custom)
 {
     using (ETicaretContext db = new ETicaretContext())
     {
         db.Custom.Add(custom);
         db.SaveChanges();
     }
 }
 public static void AddCustomer(Customer customer)
 {
     using (ETicaretContext db = new ETicaretContext())
     {
         db.Customer.Add(customer);
         db.SaveChanges();
     }
 }
示例#5
0
        static void Main(string[] args)
        {
            using (ETicaretContext db = new ETicaretContext())
            {
                Admin a = new Admin();
                a.UserName = "******";
                a.Password = "******";

                db.Admin.Add(a);

                Category c = new Category();
                c.CategoryName = "Tarih";
                db.Category.Add(c);



                Writer w = new Writer();
                w.WriterName = "Hakan";
                db.Writer.Add(w);


                Book b = new Book()
                {
                    BookName     = "bookname",
                    BookSubject  = "subject",
                    CategoryID   = 1,
                    Price        = 10,
                    WriterID     = 1,
                    PageCount    = 100,
                    BookPhotoURL = "http://placehold.it/800x300",
                };

                db.Book.Add(b);


                Customer cu = new Customer()
                {
                    NameSurname = "Hakan Karanfil",
                    Address     = "izmir",
                    Total       = 30,
                };

                db.Customer.Add(cu);

                Product s = new Product()
                {
                    BookID       = 1,
                    BookCount    = 1,
                    BookPhotoURL = "http://placehold.it/800x300",
                    BookName     = "Bookname",
                    Price        = 20,
                };

                db.Product.Add(s);

                db.SaveChanges();
            }
        }
示例#6
0
 public ActionResult SignIn(User user)
 {
     if (ModelState.IsValid)
     {
         if (db.Users.FirstOrDefault(x => x.userEmail == user.userEmail) != null)
         {
             ViewBag.result = "Email adresi zaten kayıtlı!";
             return(View());
         }
         user.userPassword = Crypto.Hash(user.userPassword, "MD5");
         db.Users.Add(user);
         db.SaveChanges();
         ViewBag.result = "Başarıyla kayıt oldunuz";
         return(View());
     }
     ViewBag.result = "Lütfen tüm alanları doldurunuz";
     return(View());
 }
示例#7
0
        public ActionResult AddtoCart(int id)
        {
            if (Session["userId"] == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            int     thisUserId  = Convert.ToInt32(Session["userId"]);
            Product thisProduct = db.Products.Find(id);

            if (db.Carts.FirstOrDefault(x => x.cartUser.userId == thisUserId) == null)
            {
                Cart cart = new Cart();
                db.Users.Find(thisUserId).cart = cart;
                db.SaveChanges();
            }
            db.Carts.Include("cartUser").FirstOrDefault(x => x.cartUser.userId == thisUserId).Products.Add(thisProduct);
            db.SaveChanges();
            return(RedirectToAction("Cart"));
        }
示例#8
0
 public ActionResult Create(Product product, HttpPostedFileBase imageUrl)
 {
     if (ModelState.IsValid)
     {
         if (imageUrl != null)
         {
             WebImage image = new WebImage(imageUrl.InputStream);
             FileInfo info  = new FileInfo(imageUrl.FileName);
             image.Resize(400, 400);
             string logoname = Guid.NewGuid().ToString() + info.Extension;
             image.Save("~/Images/" + logoname);
             product.productImageUrl = "/Images/" + logoname;
         }
         db.Products.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.categoryId = new SelectList(db.Categories, "categoryId", "categoryName", product.categoryId);
     return(View(product));
 }
示例#9
0
        public ActionResult Profile(Admin admin, string adminPasswordnew)
        {
            Admin profile = db.Admins.Find(Session["Id"]);

            if (profile == null)
            {
                return(RedirectToAction("Index"));
            }
            if (profile.adminPassword == Crypto.Hash(admin.adminPassword, "MD5"))
            {
                profile.adminPassword = Crypto.Hash(adminPasswordnew, "MD5");
                profile.adminEmail    = admin.adminEmail;
                profile.adminFullname = admin.adminFullname;
                db.SaveChanges();
                ViewBag.result = "Değişiklikler Kaydedilmiştir";
                return(RedirectToAction("Index"));
            }
            ViewBag.result = "Değişiklikler Kaydedilmemiştir";
            return(View(profile));
        }
示例#10
0
        public static Customer UpdateCustomerPassword(Customer customer, string newPassword)
        {
            using (ETicaretContext db = new ETicaretContext())
            {
                var toBeUpdated = db.Customer.Find(customer.CustomerID);
                toBeUpdated.Password = newPassword;

                db.SaveChanges();

                return(toBeUpdated);
            }
        }
示例#11
0
        public static Customer UpdateCustomerAddress(Customer customer)
        {
            using (ETicaretContext db = new ETicaretContext())
            {
                var toBeUpdated = db.Customer.Find(customer.CustomerID);

                toBeUpdated.Address = customer.Address;

                db.SaveChanges();

                return(toBeUpdated);
            }
        }
示例#12
0
        public User Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Set <User>().Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username \"" + user.UserName + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Set <User>().Add(user);
            _context.SaveChanges();

            return(user);
        }
示例#13
0
 public ActionResult Edit(int?id, Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.Result = "Bilgiler Güncellenmiştir";
     }
     else
     {
         ViewBag.Result = "Hata";
     }
     return(View(contact));
 }
示例#14
0
        public static string AddCustomer(Customer customer)
        {
            using (ETicaretContext db = new ETicaretContext())
            {
                var isThereCustomer = db.Customer.SingleOrDefault(c => c.Email == customer.Email);

                if (isThereCustomer != null)
                {
                    return("Girdiğiniz e-posta adresi zaten kullanılıyor.");
                }
                else
                {
                    db.Customer.Add(customer);
                    db.SaveChanges();
                    return("Success");
                }
            }
        }
示例#15
0
        public static void Seed()
        {
            var context = new ETicaretContext();

            //Bekleyen migration yoksa test belleğini databaseye yükle
            if (context.Database.GetPendingMigrations().Count() == 0)
            {
                //Database boşsa eklesin
                if (context.Categories.Count() == 0)
                {
                    context.Categories.AddRange(Categories);
                }

                if (context.Products.Count() == 0)
                {
                    context.Products.AddRange(Products);
                    context.AddRange(ProductCategory);
                }

                context.SaveChanges();
            }
        }
示例#16
0
 public int Save()
 {
     return(_context.SaveChanges());
 }
示例#17
0
 public int Commit()
 {
     return(Context.SaveChanges());
 }