public ActionResult LisaRaamat(Item item)
        {
            MembershipUser kasutaja = Membership.GetUser();
            Guid userID = (Guid)kasutaja.ProviderUserKey;
            try
            {
                if (ModelState.IsValid)
                {
                    Autor autor = new Autor()
                    {
                        Perekonnanimi = item.Autors.Perekonnanimi
                    };
                    db.Autors.Add(autor);
                    db.SaveChanges();
                    var autorId = (from x in db.Autors
                                   where x.Perekonnanimi == item.Autors.Perekonnanimi
                                   select x.AutorId).FirstOrDefault();

                    item.Lisatud = DateTime.Now;
                    item.CoverArtUrl = "/UploadedImages/placeholder.gif";
                    item.AutorId = autorId;
                    db.Items.Add(item);
                    db.SaveChanges();

                    var itm = (from x in db.Items
                               where x.ItemId == item.ItemId
                               select x.ItemId).FirstOrDefault();
                    string _user = User.Identity.Name;

                    var kasutajaID = (from z in db.Kasutajad
                                      where z.fk_UserId == userID
                                      select z.KasutajaId).First();
                    UserItem userItem = new UserItem()
                    {
                        Adder = _user,
                        ItemId = itm,
                        UserId = userID,
                        Added = DateTime.Now,
                        fk_KasutajaId = kasutajaID

                    };
                    db.UserItems.Add(userItem);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (DataException e)
            {

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", e.ToString());
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", item.CategoryId);
            return View(item);
        }
        public ActionResult LisaRaamat(Item item)
        {
            MembershipUser kasutaja = Membership.GetUser();
            Guid userID = (Guid)kasutaja.ProviderUserKey;
            try
            {
                if (ModelState.IsValid)
                {
                    Autor autor = new Autor()
                    {
                        Perekonnanimi = item.Autors.Perekonnanimi
                    };
                    db.Autors.Add(autor);
                    db.SaveChanges();
                    var autorId = (from x in db.Autors
                                   where x.Perekonnanimi == item.Autors.Perekonnanimi
                                   select x.AutorId).FirstOrDefault();

                    item.Lisatud = DateTime.Now;
                    item.CoverArtUrl = "/UploadedImages/placeholder.gif";
                    item.AutorId = autorId;
                    db.Items.Add(item);
                    db.SaveChanges();

                    var itm = (from x in db.Items
                               where x.ItemId == item.ItemId
                               select x.ItemId).FirstOrDefault();
                    UserItem userItem = new UserItem()
                    {
                        ItemId = itm,
                        UserId = userID

                    };
                    db.UserItems.Add(userItem);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (DataException)
            {

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", item.CategoryId);
            return View(item);
        }
        public ActionResult LisaRaamat(Item item)
        {
            MembershipUser kasutaja = Membership.GetUser();
            Guid userID = (Guid)kasutaja.ProviderUserKey;

            if (ModelState.IsValid)
            {
                Autor autor = new Autor()
                {
                    Perekonnanimi = item.Autors.Perekonnanimi
                };
                db.Autors.Add(autor);
                db.SaveChanges();
                var autorId = (from x in db.Autors
                                 where x.Perekonnanimi == item.Autors.Perekonnanimi
                                 select x.AutorId).FirstOrDefault();

                item.Lisatud = DateTime.Now;
                item.CoverArtUrl = "/Content/Images/placeholder.gif";
                item.AutorId = autorId;
                db.Items.Add(item);
                db.SaveChanges();

                var itm = (from x in db.Items
                           where x.ItemId == item.ItemId
                           select x.ItemId).FirstOrDefault();
                UserItem userItem = new UserItem()
                {
                    ItemId = itm,
                    UserId = userID

                };
                db.UserItems.Add(userItem);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", item.CategoryId);
            return View(item);
        }