Beispiel #1
0
        public ActionResult Edit(BookViewModel bookViewModel)
        {
            if (ModelState.IsValid)
            {
                Book book = db.Books.Find(bookViewModel.BookId);
                if (bookViewModel != null && bookViewModel.Photo != null)
                {
                    book.Photo = ImageConverter.ByteArrayFromPostedFile(bookViewModel.Photo);
                }

                book.PublisherId   = bookViewModel.PublisherId;
                book.CategoryId    = bookViewModel.CategoryId;
                book.LanguageId    = bookViewModel.LanguageId;
                book.Author        = bookViewModel.Author;
                book.Description   = bookViewModel.Description;
                book.BookName      = bookViewModel.BookName;
                book.Price         = bookViewModel.Price;
                book.PublishedDate = bookViewModel.PublishedDate;
                book.Stock         = bookViewModel.Stock;
                book.isAvailable   = bookViewModel.isAvailable;

                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId  = new SelectList(db.Categories, "CategoryId", "CategoryName", bookViewModel.CategoryId);
            ViewBag.LanguageId  = new SelectList(db.Languages, "LanguageId", "LanguageName", bookViewModel.LanguageId);
            ViewBag.PublisherId = new SelectList(db.Publishers, "PublisherId", "PublisherName", bookViewModel.PublisherId);
            return(View(bookViewModel));
        }
Beispiel #2
0
        public ActionResult Edit(ApplicationViewModel applicationVM)
        {
            //Application application = new Application();

            if (ModelState.IsValid)
            {
                //application.ApplicationId = UserHelper.GetUserId(db.Users, User.Identity);
                Application application = db.Applications.Find(applicationVM.ApplicationId);
                if (applicationVM != null && applicationVM.Photo != null)
                {
                    application.Photo = ImageConverter.ByteArrayFromPostedFile(applicationVM.Photo);
                }
                application.FirstName        = applicationVM.FirstName;
                application.LastName         = applicationVM.LastName;
                application.ProgarmId        = applicationVM.ProgarmId;
                application.DepartmentId     = applicationVM.DepartmentId;
                application.TelePhoneNumber  = applicationVM.TelePhoneNumber;
                application.Status           = Status.Draft;
                application.RegistrationDate = DateTime.Now;

                db.Entry(application).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.DepartmentId  = new SelectList(db.Departments, "DepartmentId", "Name", applicationVM.DepartmentId);
            ViewBag.ProgarmId     = new SelectList(db.Programs, "ProgarmId", "Name", applicationVM.ProgarmId);
            ViewBag.ApplicationId = new SelectList(db.Users, "Id", "Id", applicationVM.ApplicationId);
            return(View(applicationVM));
        }
Beispiel #3
0
        public ActionResult Create(BookViewModel bookViewModel)
        {
            if (ModelState.IsValid)
            {
                var book = new Book();
                book.PublisherId   = bookViewModel.PublisherId;
                book.Author        = bookViewModel.Author;
                book.PublishedDate = bookViewModel.PublishedDate;
                book.BookName      = bookViewModel.BookName;
                book.CategoryId    = bookViewModel.CategoryId;
                book.Description   = bookViewModel.Description;
                book.LanguageId    = bookViewModel.LanguageId;
                book.Price         = bookViewModel.Price;
                book.Stock         = bookViewModel.Stock;
                if (bookViewModel.Photo != null)
                {
                    book.Photo = ImageConverter.ByteArrayFromPostedFile(bookViewModel.Photo);
                }
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", book.CategoryId);
            //ViewBag.LanguageId = new SelectList(db.Languages, "LanguageId", "LanguageName", book.LanguageId);
            //ViewBag.PublisherId = new SelectList(db.Publishers, "PublisherId", "PublisherName", book.PublisherId);
            return(View(bookViewModel));
        }
Beispiel #4
0
        public ActionResult Edit(CarViewModel carVM)
        {
            if (ModelState.IsValid)
            {
                Car car = db.Cars.Find(carVM.CarId);
                if (carVM != null && carVM.Photo != null)
                {
                    car.Photo = ImageConverter.ByteArrayFromPostedFile(carVM.Photo);
                }
                car.RegNum            = carVM.RegNum;
                car.Make              = carVM.Make;
                car.Model             = carVM.Model;
                car.CarYear           = carVM.CarYear;
                car.CarCategory       = carVM.CarCategory;
                car.PassengerCapacity = carVM.PassengerCapacity;
                if (carVM.IsAvailable)
                {
                    car.IsAvailable = true;
                }
                else
                {
                    car.IsAvailable = false;
                }

                car.RentalFee = carVM.RentalFee;

                db.Entry(car).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(carVM));
        }
 public ActionResult Edit(StudentViewModel studentVM)
 {
     if (ModelState.IsValid)
     {
         Student student = db.Students.Find(studentVM.Id);
         if (studentVM != null && studentVM.Photo != null)
         {
             student.Photo = ImageConverter.ByteArrayFromPostedFile(studentVM.Photo);
         }
         student.Name            = studentVM.Name;
         student.EnrollmentDate  = studentVM.EnrollmentDate;
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(studentVM));
 }
        [ValidateAntiForgeryToken] // AntiForgery means nobody can steal the session
        public ActionResult Create([Bind(Include = "Id,Name,EnrollmentDate,Photo")] StudentViewModel studentVM)
        {
            if (ModelState.IsValid)
            {
                var student = new Student();
                student.Name           = studentVM.Name;
                student.EnrollmentDate = studentVM.EnrollmentDate;
                // adding photo to the object
                if (studentVM.Photo != null)
                {
                    student.Photo = ImageConverter.ByteArrayFromPostedFile(studentVM.Photo);
                }

                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(studentVM));
        }
        public ActionResult Edit(DocumentsViewModel documentsViewModel)
        {
            if (ModelState.IsValid)
            {
                EnclosedDocument enclosedDocument = db.EnclosedDocuments.Find(documentsViewModel.Id);
                enclosedDocument.ApplicationId = UserHelper.GetUserId(db.Users, User.Identity);
                enclosedDocument.DocumentType  = documentsViewModel.DocumentType;
                enclosedDocument.Name          = documentsViewModel.Name;
                if (documentsViewModel.DocumentFile != null)
                {
                    enclosedDocument.DocumentFile = ImageConverter.ByteArrayFromPostedFile(documentsViewModel.DocumentFile);
                }
                db.Entry(enclosedDocument).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ApplicationId = new SelectList(db.Applications, "ApplicationId", "ApplicationId", documentsViewModel.ApplicationId);
            return(View(documentsViewModel));
        }
        public ActionResult Create([Bind(Include = "Id,Name,EnrollmentDate,Photo")] StudentViewModel studentVM)
        {
            if (ModelState.IsValid)
            {
                //Mapper.CreateMap<StudentViewModel, Student>();
                //var student = Mapper.Map<Student>(studentVM);
                var student = new Student();
                student.Name           = studentVM.Name;
                student.EnrollmentDate = studentVM.EnrollmentDate;
                if (studentVM.Photo != null)
                {
                    student.Photo = ImageConverter.ByteArrayFromPostedFile(studentVM.Photo);
                }
                db.Students.Add(student);
                db.SaveChanges();//commit into the database
                return(RedirectToAction("Index"));
            }

            return(View(studentVM));
        }
        public ActionResult Edit(GameViewModel gameVM)
        {
            if (ModelState.IsValid)
            {
                Game game = db.Games.Find(gameVM.GameId);
                game.Title   = gameVM.Title;
                game.Summary = gameVM.Summary;
                if (gameVM != null && gameVM.Photo != null)
                {
                    game.Photo = ImageConverter.ByteArrayFromPostedFile(gameVM.Photo);
                }
                game.GameInfo        = gameVM.GameInfo;
                db.Entry(game).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.GameInfoId = new SelectList(db.GameInfoes, "GameInfoId", "Rating", "Genre", gameVM.GameInfoId);

            return(View(gameVM));
        }
        public ActionResult Create(GameViewModel gameVM)
        {
            if (ModelState.IsValid)
            {
                Game game = new Game();
                game.Title   = gameVM.Title;
                game.Summary = gameVM.Summary;
                if (gameVM.Photo != null)
                {
                    game.Photo = ImageConverter.ByteArrayFromPostedFile(gameVM.Photo);
                }
                GameInfo gameinfo = new GameInfo();
                gameinfo.Genre  = gameVM.GameInfo.Genre;
                gameinfo.Rating = gameVM.GameInfo.Rating;
                game.GameInfo   = gameinfo;
                db.Games.Add(game);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.GameInfoId = new SelectList(db.GameInfoes, "GameInfoId", "Rating", "Genre", gameVM.GameInfoId);
            return(View(gameVM));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "CarId,RegNum,Make,Model,CarYear,CarCategory,PassengerCapacity,IsAvailable,RentalFee,Photo")] CarViewModel carVM)
        {
            if (ModelState.IsValid)
            {
                var car = new Car();
                car.RegNum            = carVM.RegNum;
                car.Make              = carVM.Make;
                car.Model             = carVM.Model;
                car.CarYear           = carVM.CarYear;
                car.CarCategory       = carVM.CarCategory;
                car.PassengerCapacity = carVM.PassengerCapacity;
                car.IsAvailable       = true;
                car.RentalFee         = carVM.RentalFee;
                if (carVM.Photo != null)
                {
                    car.Photo = ImageConverter.ByteArrayFromPostedFile(carVM.Photo);
                }
                db.Cars.Add(car);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(carVM));
        }