public ActionResult ReturnShadowBook(ShadowBook shadowBook)
        {
            ShadowBook toReturn = db.tabShBook.Find(shadowBook.ShadowId);

            ///
            try
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("ShadowReturnD", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@ShadowID", toReturn.ShadowId);
                    cmd.Parameters.AddWithValue("@Id", toReturn.Id);

                    con.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
            }
            ////
            //db.tabBook.Remove(toDelete);
            db.SaveChanges();
            return(RedirectToAction("ShadowBook"));
        }
        public ActionResult Register(miniLibrary2017.Models.User user)
        {
            if (ModelState.IsValid)
            {
                using (var db = new DBminiLibrary())
                {
                    var crypto = new SimpleCrypto.PBKDF2();

                    var  entryPass = crypto.Compute(user.Password);
                    User sysUser   = new User();
                    //var sysUser = db.tabUser.Create();

                    sysUser.Login        = user.Login;
                    sysUser.Password     = entryPass;
                    sysUser.PasswordSalt = crypto.Salt;

                    db.tabUser.Add(sysUser);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
            }


            return(View(user));
        }
        public ActionResult EditAuthor(Author author)
        {
            if (ModelState.IsValid)
            {
                Author toEdit;
                if (author.Id == 0)
                {
                    toEdit = new Author();
                    db.tabAuthor.Add(author);
                }
                else
                {
                    toEdit = db.tabAuthor.Find(author.Id);
                    if (toEdit != null)
                    {
                        try
                        {
                            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                            using (SqlConnection con = new SqlConnection(CS))
                            {
                                SqlCommand cmd = new SqlCommand("AuthorEdit", con);
                                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                                cmd.Parameters.AddWithValue("@Id", toEdit.Id);
                                cmd.Parameters.AddWithValue("@Fname", toEdit.FirstName);
                                cmd.Parameters.AddWithValue("@Lname", toEdit.LastName);
                                con.Open();
                                cmd.ExecuteNonQuery();
                            }
                        }
                        catch (Exception e)
                        {
                            Response.Write(e.Message);
                        }


                        toEdit.LastName  = author.LastName;
                        toEdit.FirstName = author.FirstName;
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
예제 #4
0
        public ActionResult EditBook(Book book)
        {
            if (ModelState.IsValid)
            {
                Book toEdit;
                if (book.Id == 0)
                {
                    toEdit = new Models.Book();

                    db.tabBook.Add(book);
                }
                else
                {
                    toEdit = db.tabBook.Find(book.Id);
                    if (toEdit != null)
                    {
                        try
                        {
                            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                            using (SqlConnection con = new SqlConnection(CS))
                            {
                                SqlCommand cmd = new SqlCommand("BookEdit", con);
                                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                                cmd.Parameters.AddWithValue("@Id", toEdit.Id);
                                cmd.Parameters.AddWithValue("@Title", toEdit.Title);
                                cmd.Parameters.AddWithValue("@YearOfPublish", toEdit.YearOfPublish);
                                cmd.Parameters.AddWithValue("@ISBN", toEdit.ISBN);
                                cmd.Parameters.AddWithValue("@IdAuthor", toEdit.IdAuthor);

                                con.Open();
                                cmd.ExecuteNonQuery();
                            }
                        }
                        catch (Exception e)
                        {
                            Response.Write(e.Message);
                        }
                        toEdit.IdAuthor      = book.IdAuthor;
                        toEdit.Title         = book.Title;
                        toEdit.ISBN          = book.ISBN;
                        toEdit.YearOfPublish = book.YearOfPublish;
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <SelectListItem> listaZPoz0 = new List <SelectListItem>();

            listaZPoz0.Add(new SelectListItem {
                Text = "wybierz autora", Value = ""
            });
            List <SelectListItem> listaAutorow = (from item in db.tabAuthor
                                                  orderby item.LastName
                                                  select new SelectListItem {
                Value = item.Id.ToString(), Text = item.LastName + " " + item.FirstName
            }).ToList();

            listaZPoz0.AddRange(listaAutorow);

            ViewBag.Autorzy = listaZPoz0;
            return(View());
        }