コード例 #1
0
        //Отображение описания предприятия для пользователей
        public ActionResult UserEnterpriseDescription(int id)
        {
            Enterprise FullEnterprise = db.Enterprises.Find(id);

            ViewBag.FullEnterprise = FullEnterprise;

            string str = FullEnterprise.Description;

            if (str != null)
            {
                char ch          = '\n';
                int  indexOfChar = str.IndexOf(ch);
                int  strLength   = str.Length;

                if ((indexOfChar < strLength) && (indexOfChar >= 0))
                {
                    ViewBag.FullEnterpriseShortDescription = FullEnterprise.Description.Substring(0, indexOfChar - 1);
                }
                else
                {
                    ViewBag.FullEnterpriseShortDescription = "";
                }
            }
            else
            {
                ViewBag.FullEnterpriseShortDescription = "";
            }

            string previewDir = ConfigurationManager.AppSettings["PathToBooks"] + @"\" + id + @"\!Preview";

            if (Directory.Exists(previewDir))
            {
                var folders   = System.IO.Directory.EnumerateDirectories(previewDir);
                var galleries = folders
                                .Select(fn => Books.Create(fn))
                                .Where(g => g != null)
                                .OrderBy(g => g.OccurredOn);
                ViewBag.Books = galleries;
            }

            var EnterprisePeople = from e in db.Enterprises.Where(e => e.Id == id)
                                   join me in db.Man_Enterprises on e.Id equals me.EnterpriseId
                                   join m in db.Men on me.ManId equals m.Id
                                   select new ManEnterpriseDTO
            {
                Id    = e.Id,
                ManId = m.Id,
                Man   = m.Name,
                //Enterprise = e.Title,
                //Description = me.Description,
                //IsLeader = me.IsLeader,
                //StartDate = me.StartDate,
                //EndDate = me.EndDate
            };

            ViewBag.EnterprisePeople = EnterprisePeople.Distinct().OrderBy(s => s.Man);
            ViewBag.PeopleQuantity   = EnterprisePeople.Count();
            return(View());
        }
コード例 #2
0
        public async Task <Books> Create(CreateBook input)
        {
            Books newBook = Books.Create(input.Name, input.Author, input.Description, input.CreatorUserId);
            await _context.Books.AddAsync(newBook);

            await _context.SaveChangesAsync();

            return(newBook);
        }
コード例 #3
0
ファイル: Model.cs プロジェクト: Nodiryps/desktop_library
        public Book CreateBook(string isbn, string title, string author, string editor, int numCopies)
        {
            Book newBook = Books.Create();

            newBook.Isbn = isbn; newBook.Title = title; newBook.Author = author; newBook.Editor = editor;
            Books.Add(newBook);
            newBook.AddCopies(numCopies, DateTime.Now);
            SaveChanges();
            return(newBook);
        }
コード例 #4
0
        public Book CreateBook(String isbn, String title, String author, String editor, int numCopies = 1)
        {
            var book = Books.Create();

            book.Isbn   = isbn;
            book.Title  = title;
            book.Author = author;
            book.Editor = editor;
            DateTime n = DateTime.Now;

            Books.Add(book);
            book.AddCopies(numCopies, n);
            return(book);
        }
コード例 #5
0
        public Book CreateBook(string isbn, string title, string author, string editor, int numCopies = 1)
        {
            var book = Books.Create();

            book.Isbn   = isbn;
            book.Title  = title;
            book.Author = author;
            book.Editor = editor;
            Books.Add(book);
            SaveChanges();
            for (int i = 0; i < numCopies; ++i)
            {
                book.CreateBookCopy(DateTime.Now, book);
            }
            return(book);
        }
コード例 #6
0
        public async Task <ActionResult> Update([FromBody] BookFormModel model)
        {
            if (!Roles.IsLibrarian(User.Identity.Name) && !Roles.IsAdmin(User.Identity.Name))
            {
                return(Forbid());
            }

            var entity = Mapper.Map <Book>(model);

            foreach (BookCopieModel copie in model.BookCopies)
            {
                var library = Libraries.GetLibrary(copie.Library.LibraryId);
                if (library == null)
                {
                    return(NotFound());
                }
                if (copie.BookId != 0)
                {
                    Book book = Books.GetBook(copie.BookId);
                    book.Title         = entity.Title;
                    book.AuthorName    = entity.AuthorName;
                    book.AuthorSurname = entity.AuthorSurname;
                    book.Description   = entity.Description;
                    Books.Update(book);
                }
                else
                {
                    Book book = new Book()
                    {
                        AuthorName    = entity.AuthorName,
                        AuthorSurname = entity.AuthorSurname,
                        Description   = entity.Description,
                        Library       = library,
                        Title         = entity.Title
                    };
                    Books.Create(book);
                }
            }

            var result = Mapper.Map <BookFormModel>(entity);
            var copies = Books.GetBookCopies(entity.AuthorFullName, entity.Title);

            result.BookCopies = Mapper.Map <IEnumerable <BookCopieModel> >(copies)
                                .ForEach(x => x.Library = Mapper.Map <LibraryListItemModel>(copies.First(c => c.BookId == x.BookId).Library)).ToList();

            return(CreatedAtAction(nameof(Fetch), new { authorFullName = entity.AuthorFullName, bookTitle = entity.Title }, result));
        }
コード例 #7
0
        public Book CreateBook(string isbn, string title, string author, string editor, int numCopies)
        {
            Book book = Books.Create();

            book.Isbn   = isbn;
            book.Title  = title;
            book.Author = author;
            book.Editor = editor;

            Books.Add(book);
            BookCopy copy = App.Model.BookCopies.Create();

            copy.BookId          = book;
            copy.AcquisitionDate = DateTime.Now;
            BookCopies.Add(copy);
            SaveChanges();

            return(book);
        }
コード例 #8
0
        public Book CreateBook(
            string isbn,
            string author,
            string title,
            string editor,
            int numCopies,
            string picturePath = null)
        {
            Book b = Books.Create();

            b.Isbn        = isbn;
            b.Author      = author;
            b.Title       = title;
            b.Editor      = editor;
            b.PicturePath = picturePath;
            Books.Add(b);
            b.AddCopies(numCopies, DateTime.Now);
            SaveChanges();
            return(b);
        }