コード例 #1
0
        public ActionResult Add(User userView, HttpPostedFileBase image)
        {
            var    authorization = db.Authorizations.ToList();
            string email         = userView.email.ToUpper(new CultureInfo("tr-TR", false));

            if (ModelState.IsValid == false)
            {
                ViewBag.Authorization = new SelectList(authorization, "authorizationID", "name");
                return(View());
            }
            User userDb = db.Users.Where(x => x.email == email && x.authorizationID == userView.authorizationID).SingleOrDefault();

            if (userDb != null)
            {
                ViewBag.Hata          = "Böyle bir kullanıcı kayıtlıdır";
                ViewBag.Authorization = new SelectList(authorization, "authorizationID", "name");
                return(View());
            }
            Photograph photograph = new Photograph();

            if (image != null)
            {
                string returnValue = photograph.Add(image);
                if (returnValue == "extention")
                {
                    ViewBag.Hata          = "Resim uzantısı jpg ve png den başka olamaz";
                    ViewBag.Authorization = new SelectList(authorization, "authorizationID", "name");
                    return(View());
                }
                else if (returnValue == "length")
                {
                    ViewBag.Hata          = "Resmin boyutu maksimum 3MB olabilir";
                    ViewBag.Authorization = new SelectList(authorization, "authorizationID", "name");
                    return(View());
                }
                userView.imageName = returnValue;
            }
            else
            {
                userView.imageName = "default.jpg";
            }
            userDb                 = new User();
            userDb.name            = userView.name.ToUpper(new CultureInfo("tr-TR", false));
            userDb.surname         = userView.surname.ToUpper(new CultureInfo("tr-TR", false));
            userDb.email           = userView.email.ToUpper(new CultureInfo("tr-TR", false));
            userDb.phoneNumber     = userView.phoneNumber;
            userDb.password        = userView.password;
            userDb.authorizationID = userView.authorizationID;
            userDb.imageName       = userView.imageName;
            db.Users.Add(userDb);
            db.SaveChanges();
            TempData["Basari"]    = "Kayıt başarı ile oluşturulmuştur";
            ViewBag.Authorization = new SelectList(authorization, "authorizationID", "name");
            return(RedirectToAction("Add"));
        }
コード例 #2
0
        public ActionResult Add(Book bookView, HttpPostedFileBase image)
        {
            var category = db.Categories.ToList();

            if (ModelState.IsValid == false)
            {
                ViewBag.Category = new SelectList(category, "categoryID", "name");
                return(View());
            }
            Photograph photograph = new Photograph();

            if (image != null)
            {
                string returnValue = photograph.Add(image, "/Content/Photograph/Book/");
                if (returnValue == "extention")
                {
                    ViewBag.Hata     = "Resim uzantısı jpg ve png den başka olamaz";
                    ViewBag.Category = new SelectList(category, "categoryID", "name");
                    return(View());
                }
                else if (returnValue == "length")
                {
                    ViewBag.Hata     = "Resmin boyutu maksimum 3MB olabilir";
                    ViewBag.Category = new SelectList(category, "categoryID", "name");
                    return(View());
                }
                bookView.imageName = returnValue;
            }
            else
            {
                bookView.imageName = "default.jpg";
            }
            Book book = new Book();

            book.name          = bookView.name.ToUpper(new CultureInfo("tr-TR", false));
            book.writer        = bookView.writer.ToUpper(new CultureInfo("tr-TR", false));
            book.publisher     = bookView.publisher.ToUpper(new CultureInfo("tr-TR", false));
            book.numberOfPages = bookView.numberOfPages;
            book.statusID      = 1;
            book.categoryID    = bookView.categoryID;
            book.imageName     = bookView.imageName;
            db.Books.Add(book);
            db.SaveChanges();
            TempData["Basari"] = "Kayıt başarı ile oluşturulmuştur";
            ViewBag.Category   = new SelectList(category, "categoryID", "name");
            return(RedirectToAction("Add"));
        }