Exemplo n.º 1
0
        public ActionResult Update(MyBookCRUDModel model)
        {
            if (Session["LoggedUser"] != null)
            {
                MyBook myBook = myBookOperation.GetById(model.BookId);

                myBook.BookId     = model.BookId;
                myBook.Name       = model.Name;
                myBook.Writer     = model.Writer;
                myBook.Image      = model.ImagePath;
                myBook.CategoryId = model.CategoryId;

                #region Upload

                string Imagee = string.Empty;

                if (model.ImageFile != null)
                {
                    Imagee = model.ImageFile.FileName;
                    model.ImageFile.SaveAs(Server.MapPath("~/Content/Picture/") + model.ImageFile.FileName);
                    myBook.Image = Imagee;
                }
                #endregion

                myBookOperation.Update(myBook);
            }

            return(RedirectToAction("Index", "MyBook"));
        }
Exemplo n.º 2
0
        public ActionResult Update(int id = 0)
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                MyBook myBook = myBookOperation.GetById(id);

                if (myBook != null)
                {
                    MyBookCRUDModel myBookCRUDModel = new MyBookCRUDModel();


                    List <Category> categoryList = categoryOperation.GetAllCategory(appUser.AppUserId);
                    myBookCRUDModel.CategoryList = new SelectList(categoryList, "CategoryId", "Name");

                    myBookCRUDModel.BookId     = myBook.BookId;
                    myBookCRUDModel.Name       = myBook.Name;
                    myBookCRUDModel.Writer     = myBook.Writer;
                    myBookCRUDModel.ImagePath  = myBook.Image;
                    myBookCRUDModel.CategoryId = myBook.CategoryId;

                    return(View(myBookCRUDModel));
                }
                else
                {
                    return(RedirectToAction("Index", "MyBook"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Exemplo n.º 3
0
        public ActionResult Insert(int id = 0)
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                MyBookCRUDModel myBookCRUDModel = new MyBookCRUDModel();

                List <Category> categoryList = categoryOperation.GetAllCategory(appUser.AppUserId);
                myBookCRUDModel.CategoryList = new SelectList(categoryList, "CategoryId", "Name");

                return(View(myBookCRUDModel));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Exemplo n.º 4
0
        public ActionResult Insert(MyBookCRUDModel model)
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                #region Upload

                string Imagee = string.Empty;

                if (model.ImageFile != null)
                {
                    Imagee = model.ImageFile.FileName;
                    model.ImageFile.SaveAs(Server.MapPath("~/Content/Picture/") + model.ImageFile.FileName);
                }

                #endregion


                MyBook myBook = new MyBook()
                {
                    BookId     = model.BookId,
                    AppUserId  = appUser.AppUserId,
                    Name       = model.Name,
                    Writer     = model.Writer,
                    CategoryId = model.CategoryId,
                    Image      = Imagee,
                    IsActive   = true
                };
                myBookOperation.Insert(myBook);

                return(RedirectToAction("Index", "MyBook"));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }