Beispiel #1
0
        public ActionResult BookNew(int id)
        {
            Rep_Book     rep   = new Rep_Book();
            BookNewModel model = new BookNewModel();

            model.DetailsNav = rep.Get_BookDetailsListByBookType(id);
            model.ID         = id;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult BookNew(BookNewModel model)
        {
            Tbl_Book        _book    = new Tbl_Book();
            Tbl_BookDetails _details = new Tbl_BookDetails();
            Tbl_BookAcsses  _acsses  = new Tbl_BookAcsses();

            Membership membership = new Membership();
            Rep_Book   rep        = new Rep_Book();

            model.DetailsNav = rep.Get_BookDetailsListByBookType(model.ID);

            _book.Book_Code           = model.Book.Book_Code;
            _book.Book_Name           = model.Book.Book_Name;
            _book.Book_BookTypeID     = model.ID;
            _book.Book_UploaderUserID = membership.Get_IDByUserName(User.Identity.Name);
            _book.Book_Publish        = false;

            _details.BD_DigitalVersionAvailable = model.Details.BD_DigitalVersionAvailable;

            if (model.Details.BD_DigitalVersionAvailable)
            {
                _details.BD_FileEnabel = true;
            }


            _details.BD_PhysicalVersionAvailable = model.Details.BD_PhysicalVersionAvailable;



            if (model.Details.BD_PhysicalVersionAvailable)
            {
                _details.BD_LibraryID = model.Details.BD_LibraryID;
            }

            _details.BD_PageCount = model.Details.BD_PageCount;

            _details.BD_LanguageID = model.Details.BD_LanguageID;

            foreach (var item in model.DetailsNav)
            {
                switch (item)
                {
                case "Titel":
                    _details.BD_Titel = model.Details.BD_Titel;
                    break;

                case "Abstract":
                    _details.BD_Abstract = model.Details.BD_Abstract;
                    break;

                case "Student":
                    _details.BD_StudentID = model.Details.BD_StudentID;
                    break;

                case "Master":
                    _details.BD_MasterID = model.Details.BD_MasterID;
                    break;

                case "ISBN":
                    _details.BD_ISBN = model.Details.BD_ISBN;
                    break;

                case "Group":
                    _details.BD_GroupID = model.Details.BD_GroupID;
                    break;

                case "Branch":
                    _details.BD_BranchID = model.Details.BD_BranchID;
                    break;

                case "Publishers":
                    _details.BD_Publishers = model.Details.BD_Publishers;
                    break;

                case "Subject":
                    _details.BD_Subject = model.Details.BD_Subject;
                    break;

                case "Description":
                    _details.BD_Description = model.Details.BD_Description;
                    break;

                case "WriterName":
                    _details.BD_WriterName = model.Details.BD_WriterName;
                    break;

                case "ReleaseCount":
                    _details.BD_ReleaseCount = model.Details.BD_ReleaseCount;
                    break;

                case "Translator":
                    _details.BD_Translator = model.Details.BD_Translator;
                    break;

                default:
                    break;
                }
            }

            _acsses.BookAcsses_Guest  = false;
            _acsses.BookAcsses_Global = false;
            _acsses.BookAcsses_Local  = false;
            _acsses.BookAcsses_Custom = false;

            db.Tbl_BookDetails.Add(_details);
            db.Tbl_BookAcsses.Add(_acsses);

            _book.Tbl_BookDetails = _details;
            _book.Tbl_BookAcsses  = _acsses;

            db.Tbl_Book.Add(_book);

            foreach (var item in model.Tag)
            {
                Tbl_BookTag _booktag = new Tbl_BookTag();

                int id = 0;

                if (Int32.TryParse(item, out id))
                {
                    Tbl_Tag tag = db.Tbl_Tag.Where(a => a.Tag_ID == id).SingleOrDefault();

                    if (tag == null)
                    {
                        Tbl_Tag _tag = new Tbl_Tag();
                        _tag.Tag_Name = item;
                        db.Tbl_Tag.Add(_tag);

                        _booktag.Tbl_Tag  = _tag;
                        _booktag.Tbl_Book = _book;
                    }
                    else
                    {
                        _booktag.Tbl_Tag  = tag;
                        _booktag.Tbl_Book = _book;
                    }
                }
                else
                {
                    Tbl_Tag _tag = new Tbl_Tag();
                    _tag.Tag_Name = item;
                    db.Tbl_Tag.Add(_tag);

                    _booktag.Tbl_Tag  = _tag;
                    _booktag.Tbl_Book = _book;
                }


                db.Tbl_BookTag.Add(_booktag);
            }

            if (Convert.ToBoolean(db.SaveChanges() > 0))
            {
                ViewBag.Message = "عملبات با موفقیت انجام شده!";
                ViewBag.State   = "Sucsse";
                if (_details.BD_DigitalVersionAvailable)
                {
                    return(RedirectToAction("BookUplaod", "Book", new { id = _book.Book_ID }));
                }
                else
                {
                    if (User.IsInRole("Publish"))
                    {
                        return(RedirectToAction("BookPublish", "Book", new { id = _book.Book_ID }));
                    }
                    return(RedirectToAction("BookList", "Book"));
                }
            }
            else
            {
                ViewBag.Message = "عملبات با موفقیت انجام نشده!";
                ViewBag.State   = "Error";
                return(RedirectToAction("BookNew", "Book", new { id = model.ID }));
            }
        }