Ejemplo n.º 1
0
        public async Task <ActionResult> Create([Bind(Include = "AttributeID,Name,AttributeTypeID")] ExtraAttribute extraAttribute)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.ExtraAttributes.Add(extraAttribute);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Create", "BookAddAttributes"));
                }

                ViewBag.AttributeTypeID = new SelectList(db.AttributeTypes, "AttributeTypeID", "Name", extraAttribute.AttributeTypeID);
                return(RedirectToAction("Create", "BookAddAttributes"));
            }
            catch
            {
                return(PartialView("Error404"));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create([Bind(Include = "BookID,Title,AuthorID,CountryID,Price,Description,PagesCount,Picture")] Book book, HttpPostedFileBase image1)
        {
            try
            {
                UserBook userBookAssociation = new UserBook();
                var      userName            = User.Identity.Name;
                var      query = db.AspNetUsers.Where(a => a.UserName == userName).FirstOrDefault();

                if (image1 != null)
                {
                    FileInfo file     = new FileInfo(image1.FileName);
                    var      fileName = Path.GetFileName(image1.FileName);
                    string   GuIdName = Guid.NewGuid().ToString() + file.Extension;// stugel vor miayn picture tipi filer pahi
                    var      path     = Path.Combine(Server.MapPath("~/Picture/"), GuIdName);
                    book.Picture = GuIdName;
                    image1.SaveAs(path);
                }
                else
                {
                    book.Picture = "noimg.gif";
                }
                db.Books.Add(book);
                await db.SaveChangesAsync();

                book = db.Books.Where(b => b.Title == book.Title).FirstOrDefault();
                if (query.Id != null)
                {
                    userBookAssociation.UserID = query.Id;
                    userBookAssociation.BookID = book.BookID;
                    db.UserBooks.Add(userBookAssociation);
                    await db.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(PartialView("Error404"));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "BookAddAttributesID,BookID,AttributeID,ValueTypeText,ValueTypeDate,Ganre,GanreID")] BookAddAttribute bookAddAttribute)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.BookAddAttributes.Add(bookAddAttribute);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }

                ViewBag.BookID      = new SelectList(db.Books, "BookID", "Title", bookAddAttribute.BookID);
                ViewBag.AttributeID = new SelectList(db.ExtraAttributes, "AttributeID", "Name", bookAddAttribute.AttributeID);
                ViewBag.GanreID     = new SelectList(db.Ganres, "GanreID", "GanreName", bookAddAttribute.GanreID);
                return(View(bookAddAttribute));
            }
            catch
            {
                return(PartialView("Error404"));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create([Bind(Include = "AuthorID,AuthorName,AuthorLastName,BirthDay,Picture")] Author author, HttpPostedFileBase image1)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (image1 != null)
                    {
                        author.Picture = new byte[image1.ContentLength];
                        image1.InputStream.Read(author.Picture, 0, image1.ContentLength);
                    }
                    db.Authors.Add(author);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Create", "Books"));
                }

                return(View(author));
            }
            catch
            {
                return(PartialView("Error404"));
            }
        }