public virtual CustomActionResult Validate(ViewModels.BookDto 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 Fill(Models.Book entity, ViewModels.BookDto book) { entity.Id = book.Id; entity.Title = book.Title; entity.ISBN = book.ISBN; entity.DateRelease = book.DateRelease; entity.PublisherId = book.PublisherId; 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; }
public static void FillDto(Models.ViewBookApplicableEmployee entity, ViewModels.BookDto 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.Keywords = entity.Keywords; book.Authors = entity.Authors; book.IsVisited = entity.IsVisited; book.IsDownloaded = entity.IsDownloaded; book.DateVisit = entity.DateVisit; book.DateDownload = entity.DateDownload; }
internal void FillBookFiles(Models.Book entity, ViewModels.BookDto 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, 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 FillBookKeywords(Models.Book entity, ViewModels.BookDto 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.BookDto 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, }); } }
internal void FillBookAuthors(Models.Book entity, ViewModels.BookDto 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 void FillDto(Models.Book entity, ViewModels.BookDto book) { book.Id = entity.Id; book.Title = entity.Title; book.ISBN = entity.ISBN; book.DateRelease = entity.DateRelease; book.PublisherId = entity.PublisherId; 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; }
public async Task <IHttpActionResult> PostBook(ViewModels.BookDto 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.BookDto.Fill(entity, dto); unitOfWork.BookRepository.FillBookRelatedAircraftTypes(entity, dto); unitOfWork.BookRepository.FillBookRelatedEmployees(entity, dto); unitOfWork.BookRepository.FillBookRelatedGroups(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); } string webUrl = ConfigurationManager.AppSettings["web"] + "downloadhandler.ashx?t=bookarchive&id=" + entity.Id; object input = new { }; string inputJson = Newtonsoft.Json.JsonConvert.SerializeObject(input); //string inputJson = (new JavaScriptSerializer()).Serialize(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)); }
public async Task <ViewModels.BookDto> GetBookDto(int id) { var book = new ViewModels.BookDto(); var dbbook = await context.Books.FirstOrDefaultAsync(q => q.Id == id); ViewModels.BookDto.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.BookDto> GetEmployeeBookDto(int id, int employeeId) { var book = new ViewModels.BookDto(); var dbbook = await context.ViewBookApplicableEmployees.FirstOrDefaultAsync(q => q.BookId == id && q.EmployeeId == employeeId); ViewModels.BookDto.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); }