public static BookStoreAdmin.ViewModels.Book AddBook(BookStoreAdmin.ViewModels.BookRequest objBookRequest) { BookStoreAdmin.Models.book book = new book(); BookStoreAdmin.ViewModels.Book objBook = new ViewModels.Book(); using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1()) { book.title = objBookRequest.title; book.description = objBookRequest.description; book.fk_category_id = objBookRequest.category; book.price = objBookRequest.price; foreach (int authorId in objBookRequest.authors) { book.authors.Add(new Models.author() { id = authorId }); } book.created_on = new DateTimeOffset(); context.books.Add(book); foreach (BookStoreAdmin.Models.author author in book.authors) { context.Entry(author).State = System.Data.Entity.EntityState.Unchanged; } context.SaveChanges(); } using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1()) { objBook = context.books .Where(b => b.id == book.id) .Select(book1 => new BookStoreAdmin.ViewModels.Book() { id = book1.id, title = book1.title, description = book1.description, category = new ViewModels.Category() { id = book1.category.id, description = book1.category.description, name = book1.category.name }, authors = book1.authors.Select((author) => new BookStoreAdmin.ViewModels.Author() { id = author.id, description = author.description, first_name = author.first_name, last_name = author.last_name }).ToList(), price = book1.price }).Single(); } return(objBook); }
public virtual CustomActionResult Validate(ViewModels.Book dto) { //var c = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.DateStart == dto.DateStart && q.CourseTypeId == dto.CourseTypeId && q.OrganizationId == dto.OrganizationId); // if (c != null) // return Exceptions.getDuplicateException("Course-01", "Type-Organization-DateStart"); return(new CustomActionResult(HttpStatusCode.OK, "")); }
public static void FillDto(Models.ViewBookApplicableEmployee entity, ViewModels.Book book) { book.Id = entity.BookId; book.Title = entity.Title; book.ISBN = entity.ISBN; book.DateRelease = entity.DateRelease; book.PublisherId = entity.PublisherId; book.Publisher = entity.Publisher; book.Category = entity.Category; book.ISSNPrint = entity.ISSNPrint; book.ISSNElectronic = entity.ISSNElectronic; book.DOI = entity.DOI; book.Pages = entity.Pages; book.CategoryId = entity.CategoryId; book.CustomerId = entity.CustomerId; book.Abstract = entity.Abstract; book.DateCreate = entity.DateCreate; book.DateRelease = entity.DateRelease; book.DateExposure = entity.DateExposure; book.ImageUrl = entity.ImageUrl; book.IsExposed = entity.IsExposed == 1; book.DateDeadline = entity.DateDeadline; book.Duration = entity.Duration; book.LanguageId = entity.LanguageId; book.Language = entity.Language; book.ExternalUrl = entity.ExternalUrl; book.NumberOfLessens = entity.NumberOfLessens; book.TypeId = entity.TypeId; book.JournalId = entity.JournalId; book.Journal = entity.Journal; book.Conference = entity.Conference; book.ConferenceLocationId = entity.ConferenceLocationId; book.DateConference = entity.DateConference; book.Sender = entity.Sender; book.No = entity.No; book.PublishedIn = entity.PublishedIn; book.INSPECAccessionNumber = entity.INSPECAccessionNumber; book.Edition = entity.Edition; book.DateEffective = entity.DateEffective; // book.Issue = entity.Issue; book.Keywords = entity.Keywords; book.Authors = entity.Authors; book.IsVisited = entity.IsVisited; book.IsDownloaded = entity.IsDownloaded; book.DateVisit = entity.DateVisit; book.DateDownload = entity.DateDownload; book.DateValidUntil = entity.DateValidUntil; book.DeadLine = entity.DeadLine; }
public static void Fill(Models.Book entity, ViewModels.Book book) { entity.Id = book.Id; entity.Title = book.Title; entity.ISBN = book.ISBN; entity.DateRelease = book.DateRelease; entity.PublisherId = book.PublisherId; entity.FolderId = book.FolderId; entity.ISSNPrint = book.ISSNPrint; entity.ISSNElectronic = book.ISSNElectronic; entity.DOI = book.DOI; entity.Pages = book.Pages; entity.CategoryId = book.CategoryId; entity.CustomerId = book.CustomerId; entity.Abstract = book.Abstract; entity.DateCreate = book.DateCreate; entity.DatePublished = book.DatePublished; if (book.IsExposed == true && entity.DatePublished == null) { entity.DatePublished = DateTime.Now; } if (book.IsExposed == false || book.IsExposed == null) { entity.DatePublished = null; } entity.ImageUrl = book.ImageUrl; if (entity.Id == -1) { entity.DateCreate = DateTime.Now; } entity.DateDeadline = book.DateDeadline; entity.Duration = book.Duration; entity.LanguageId = book.LanguageId; entity.ExternalUrl = book.ExternalUrl; entity.NumberOfLessens = book.NumberOfLessens; entity.TypeId = book.TypeId; entity.JournalId = book.JournalId; entity.Conference = book.Conference; entity.ConferenceLocationId = book.ConferenceLocationId; entity.DateConference = book.DateConference; entity.Sender = book.Sender; entity.No = book.No; entity.PublishedIn = book.PublishedIn; entity.INSPECAccessionNumber = book.INSPECAccessionNumber; entity.Edition = book.Edition; entity.DateEffective = book.DateEffective; entity.Issue = book.Issue; entity.DeadLine = book.DeadLine; entity.DateValidUntil = book.DateValidUntil; entity.BookKey = book.BookKey; }
internal void FillBookFiles(Models.Book entity, ViewModels.Book dto) { var existing = this.context.BookFiles.Where(q => q.BookId == entity.Id).ToList(); var deleted = (from x in existing where dto.BookFiles.FirstOrDefault(q => q.Id == x.Id) == null select x).ToList(); var added = (from x in dto.BookFiles where existing.FirstOrDefault(q => q.Id == x.Id) == null select x).ToList(); var edited = (from x in existing where dto.BookFiles.FirstOrDefault(q => q.Id == x.Id) != null select x).ToList(); foreach (var x in deleted) { context.BookFiles.Remove(x); } foreach (var x in added) { context.BookFiles.Add(new BookFile() { Book = entity, ChapterId = x.ChapterId, Remark = x.Remark, Document = new Models.Document() { DocumentTypeId = x.DocumentTypeId, FileType = x.FileType, FileTypeId = x.FileTypeId, FileUrl = x.FileUrl, SysUrl = x.SysUrl, Title = x.Title, } }); } foreach (var x in edited) { var item = dto.BookFiles.FirstOrDefault(q => q.Id == x.Id); if (item != null) { x.Remark = item.Remark; } } }
internal void FillBookRelatedTypeGroups(Models.Book entity, ViewModels.Book dto) { //var existing = this.context.BookRelatedGroups.Where(q => q.BookId == entity.Id).ToList(); //while (existing.Count > 0) //{ // var i = existing.First(); // this.context.BookRelatedGroups.Remove(i); // existing.Remove(i); //} //foreach (var x in dto.BookRelatedTypeGroups) // this.context.BookRelatedGroups.Add(new Models.BookRelatedGroup() // { // Book = entity, // GroupId = x.Id, // TypeId=x.TypeId, // }); }
internal void FillBookKeywords(Models.Book entity, ViewModels.Book dto) { var existing = this.context.BookKeywords.Where(q => q.BookId == entity.Id).ToList(); while (existing.Count > 0) { var i = existing.First(); this.context.BookKeywords.Remove(i); existing.Remove(i); } foreach (var x in dto.BookKeywords) { this.context.BookKeywords.Add(new BookKeyword() { Book = entity, Value = x.ToLower(), }); } }
internal void FillBookRelatedStudyFields(Models.Book entity, ViewModels.Book dto) { var existing = this.context.BookRelatedStudyFields.Where(q => q.BookId == entity.Id).ToList(); while (existing.Count > 0) { var i = existing.First(); this.context.BookRelatedStudyFields.Remove(i); existing.Remove(i); } foreach (var x in dto.BookRelatedStudyFields) { this.context.BookRelatedStudyFields.Add(new Models.BookRelatedStudyField() { Book = entity, StudyFieldId = x.Id, }); } }
public static void FillDto(Models.Book entity, ViewModels.Book book) { book.Id = entity.Id; book.Title = entity.Title; book.ISBN = entity.ISBN; book.DateRelease = entity.DateRelease; book.PublisherId = entity.PublisherId; book.FolderId = entity.FolderId; book.ISSNPrint = entity.ISSNPrint; book.ISSNElectronic = entity.ISSNElectronic; book.DOI = entity.DOI; book.Pages = entity.Pages; book.CategoryId = entity.CategoryId; book.CustomerId = entity.CustomerId; book.Abstract = entity.Abstract; book.DateCreate = entity.DateCreate; book.DatePublished = entity.DatePublished; book.ImageUrl = entity.ImageUrl; book.IsExposed = entity.DatePublished != null; book.DateDeadline = entity.DateDeadline; book.Duration = entity.Duration; book.LanguageId = entity.LanguageId; book.ExternalUrl = entity.ExternalUrl; book.NumberOfLessens = entity.NumberOfLessens; book.TypeId = entity.TypeId; book.JournalId = entity.JournalId; book.Conference = entity.Conference; book.ConferenceLocationId = entity.ConferenceLocationId; book.DateConference = entity.DateConference; book.Sender = entity.Sender; book.No = entity.No; book.PublishedIn = entity.PublishedIn; book.INSPECAccessionNumber = entity.INSPECAccessionNumber; book.Edition = entity.Edition; book.DateEffective = entity.DateEffective; book.Issue = entity.Issue; book.DeadLine = entity.DeadLine; book.DateValidUntil = entity.DateValidUntil; book.BookKey = entity.BookKey; }
internal void FillBookAuthors(Models.Book entity, ViewModels.Book dto) { var existing = this.context.BookAutors.Where(q => q.BookId == entity.Id && q.TypeId == 1).ToList(); while (existing.Count > 0) { var i = existing.First(); this.context.BookAutors.Remove(i); existing.Remove(i); } foreach (var x in dto.BookAuthors) { this.context.BookAutors.Add(new Models.BookAutor() { Book = entity, TypeId = 1, PersonMiscId = x, }); } }
public static BookStoreAdmin.ViewModels.Book EditBook(BookStoreAdmin.ViewModels.BookRequest objBookRequest) { BookStoreAdmin.Models.book book = new Models.book(); List <int> intAuthorids = new List <int>(); BookStoreAdmin.ViewModels.Book objBook = new ViewModels.Book(); using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1()) { book = context.books.Include("authors").Single(b => b.id == objBookRequest.id); foreach (var author in book.authors.ToList()) { if (!objBookRequest.authors.Contains(author.id)) { book.authors.Remove(author); } } foreach (var newAuthorId in objBookRequest.authors) { // Add the roles which are not in the list of user's roles if (!book.authors.Any(r => r.id == newAuthorId)) { var newAuthor = new author { id = newAuthorId }; context.authors.Attach(newAuthor); book.authors.Add(newAuthor); } } book.title = objBookRequest.title; book.description = objBookRequest.description; book.price = objBookRequest.price; book.fk_category_id = objBookRequest.category; context.SaveChanges(); } using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1()) { objBook = context.books .Where(b => b.id == book.id) .Select(book1 => new BookStoreAdmin.ViewModels.Book() { id = book1.id, title = book1.title, description = book1.description, category = new ViewModels.Category() { id = book1.category.id, description = book1.category.description, name = book1.category.name }, authors = book1.authors.Select((author) => new BookStoreAdmin.ViewModels.Author() { id = author.id, description = author.description, first_name = author.first_name, last_name = author.last_name }).ToList(), price = book1.price }).Single(); } return(objBook); }
public async Task <ViewModels.Book> GetEmployeeBookDto(int id, int employeeId) { var book = new ViewModels.Book(); var dbbook = await context.ViewBookApplicableEmployees.FirstOrDefaultAsync(q => q.BookId == id && q.EmployeeId == employeeId); ViewModels.Book.FillDto(dbbook, book); var dbbookfiles = await this.context.ViewBookFiles.Where(q => q.BookId == id).ToListAsync(); book.BookFiles = new List <ViewBookFileX>(); foreach (var x in dbbookfiles) { var bf = new ViewBookFileX(); ViewBookFileX.FillDto(x, bf); book.BookFiles.Add(bf); } //book.BookKeywords = await context.BookKeywords.Where(q => q.BookId == id).Select(q => q.Value).ToListAsync(); //book.BookAuthors = await context.BookAutors.Where(q => q.BookId == id).Select(q => q.PersonMiscId).ToListAsync(); //book.BookRelatedAircraftTypes = (await (from x in context.BookRelatedAircraftTypes // join y in context.ViewAircraftTypes on x.AircraftTypeId equals y.Id // where x.BookId == id // select y).ToListAsync()).Select(q => new ViewModels.AircraftType() // { // Id = q.Id, // Manufacturer = q.Manufacturer, // ManufacturerId = q.ManufacturerId, // Remark = q.Remark, // Type = q.Type // }).ToList(); //book.BookRelatedEmployees = (await (from x in context.BookRelatedEmployees // join y in context.ViewEmployees on x.EmployeeId equals y.Id // where x.BookId == id // select y).ToListAsync()).Select(q => new ViewModels.EmployeeView() // { // Name = q.Name, // NID = q.NID, // PID = q.PID, // Location = q.Location, // CaoCardNumber = q.CaoCardNumber, // NDTNumber = q.NDTNumber, // DateJoinCompany = q.DateJoinCompany, // Id = q.Id, // IDNo = q.IDNo, // }).ToList(); //book.BookRelatedGroups = (await (from x in context.BookRelatedGroups // join y in context.ViewJobGroups on x.GroupId equals y.Id // where x.BookId == id // select y).ToListAsync()).Select(q => new ViewModels.JobGroup() // { // Title = q.Title, // FullCode = q.FullCode, // Remark = q.Remark, // Parent = q.Parent, // Id = q.Id, // }).ToList(); //book.BookRelatedStudyFields = (await (from x in context.BookRelatedStudyFields // join y in context.ViewOptions on x.StudyFieldId equals y.Id // where x.BookId == id // select y).ToListAsync()).Select(q => new ViewModels.Option() // { // Title = q.Title, // Parent = q.Parent, // Id = q.Id, // }).ToList(); return(book); }
public async Task <ViewModels.Book> GetBookDto(int id) { var book = new ViewModels.Book(); var dbbook = await context.Books.FirstOrDefaultAsync(q => q.Id == id); ViewModels.Book.FillDto(dbbook, book); var dbbookfiles = await this.context.ViewBookFiles.Where(q => q.BookId == id).ToListAsync(); book.BookFiles = new List <ViewBookFileX>(); foreach (var x in dbbookfiles) { var bf = new ViewBookFileX(); ViewBookFileX.FillDto(x, bf); book.BookFiles.Add(bf); } book.BookKeywords = await context.BookKeywords.Where(q => q.BookId == id).Select(q => q.Value).ToListAsync(); book.BookAuthors = await context.BookAutors.Where(q => q.BookId == id).Select(q => q.PersonMiscId).ToListAsync(); book.BookRelatedAircraftTypes = (await(from x in context.BookRelatedAircraftTypes join y in context.ViewAircraftTypes on x.AircraftTypeId equals y.Id where x.BookId == id select y).ToListAsync()).Select(q => new ViewModels.AircraftType() { Id = q.Id, Manufacturer = q.Manufacturer, ManufacturerId = q.ManufacturerId, Remark = q.Remark, Type = q.Type }).ToList(); book.BookRelatedEmployees = (await(from x in context.BookRelatedEmployees join y in context.ViewEmployees on x.EmployeeId equals y.Id where x.BookId == id select y).ToListAsync()).Select(q => new ViewModels.EmployeeView() { Name = q.Name, NID = q.NID, PID = q.PID, Location = q.Location, CaoCardNumber = q.CaoCardNumber, NDTNumber = q.NDTNumber, DateJoinCompany = q.DateJoinCompany, Id = q.Id, IDNo = q.IDNo, }).ToList(); book.BookRelatedGroups = (await(from x in context.BookRelatedGroups join y in context.ViewJobGroups on x.GroupId equals y.Id where x.BookId == id select new { y, x.TypeId }).ToListAsync()).Select(q => new ViewModels./*JobGroup*/ BookTypeGroup() { Title = q.y.Title, FullCode = q.y.FullCode, Remark = q.y.Remark, Parent = q.y.Parent, Id = q.y.Id, TypeId = q.TypeId ?? -1, Type = getTypeByTypeId(q.TypeId) }).ToList(); book.BookRelatedStudyFields = (await(from x in context.BookRelatedStudyFields join y in context.ViewOptions on x.StudyFieldId equals y.Id where x.BookId == id select y).ToListAsync()).Select(q => new ViewModels.Option() { Title = q.Title, Parent = q.Parent, Id = q.Id, }).ToList(); book.Chapters = await context.ViewBookChapters.Where(q => q.BookId == id).OrderBy(q => q.Fullcode).ToListAsync(); return(book); }
public async Task <IHttpActionResult> PostBook(ViewModels.Book dto) { // return Ok(client); if (dto == null) { return(Exceptions.getNullException(ModelState)); } if (!ModelState.IsValid) { // return BadRequest(ModelState); return(Exceptions.getModelValidationException(ModelState)); } var validate = unitOfWork.BookRepository.Validate(dto); if (validate.Code != HttpStatusCode.OK) { return(validate); } Book entity = null; if (dto.Id == -1) { entity = new Book(); unitOfWork.BookRepository.Insert(entity); } else { entity = await unitOfWork.BookRepository.GetByID(dto.Id); } if (entity == null) { return(Exceptions.getNotFoundException()); } //ViewModels.Location.Fill(entity, dto); ViewModels.Book.Fill(entity, dto); unitOfWork.BookRepository.FillBookRelatedAircraftTypes(entity, dto); unitOfWork.BookRepository.FillBookRelatedEmployees(entity, dto); unitOfWork.BookRepository.FillBookRelatedGroups(entity, dto); //unitOfWork.BookRepository.FillBookRelatedTypeGroups(entity, dto); unitOfWork.BookRepository.FillBookRelatedStudyFields(entity, dto); unitOfWork.BookRepository.FillBookAuthors(entity, dto); unitOfWork.BookRepository.FillBookKeywords(entity, dto); unitOfWork.BookRepository.FillBookFiles(entity, dto); var saveResult = await unitOfWork.SaveAsync(); if (saveResult.Code != HttpStatusCode.OK) { return(saveResult); } await unitOfWork.BookRepository.UpdateChapters(entity.BookKey, entity.Id); saveResult = await unitOfWork.SaveAsync(); if (saveResult.Code != HttpStatusCode.OK) { return(saveResult); } //string webUrl = ConfigurationManager.AppSettings["web"] + "downloadhandler.ashx?t=bookarchive&id=" + entity.Id; //object input = new //{ //}; //string inputJson = Newtonsoft.Json.JsonConvert.SerializeObject(input); //WebClient client = new WebClient(); //client.Headers["Content-type"] = "application/json"; //client.Encoding = Encoding.UTF8; //string json = client.UploadString(webUrl, inputJson); dto.Id = entity.Id; return(Ok(dto)); }