public async Task <ActionResult <AcademicTitle> > PostAcademicTitle(AcademicTitle academicTitle) { _context.AcademicTitle.Add(academicTitle); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAcademicTitle", new { id = academicTitle.id }, academicTitle)); }
public async Task <LecturalDTO> AddLecturalAsync(LecturalDTO lecturalDTO) { MilitaryRank militaryRank = await _context.MilitaryRank.Where(c => c.name == lecturalDTO.MilitaryRank).FirstOrDefaultAsync(); Position position = await _context.Position.Where(c => c.name == lecturalDTO.Position).FirstOrDefaultAsync(); AcademicDegree academicDegree = await _context.AcademicDegree.Where(c => c.name == lecturalDTO.AcademicDegree).FirstOrDefaultAsync(); AcademicTitle academicTitle = await _context.AcademicTitle.Where(c => c.name == lecturalDTO.AcademicTitle).FirstOrDefaultAsync(); Lectural newLecture = new Lectural(lecturalDTO, militaryRank, position, academicDegree, academicTitle); try { _context.Lectural.Add(newLecture); await _context.SaveChangesAsync(); return(lecturalDTO); } catch (DbUpdateConcurrencyException) { if (!LecturalExists(lecturalDTO.id)) { return(null); } else { throw; } } }
public async Task <IActionResult> PutAcademicTitle(Guid id, AcademicTitle academicTitle) { if (id != academicTitle.id) { return(BadRequest()); } _context.Entry(academicTitle).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AcademicTitleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task SaveAsync(AcademicTitle entity) { try { if (entity == null) { return; } using (var timeLineContext = _contextFactory.GetTimeLineContext()) { var entityModel = await timeLineContext .AcademicTitles .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id)); if (entityModel == null) { entityModel = new DA.AcademicTitle(); MapForUpdateentity(entity, entityModel); await timeLineContext.AcademicTitles.AddAsync(entityModel); } else { MapForUpdateentity(entity, entityModel); } timeLineContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Put([FromBody] AcademicTitle value) { try { var entity = _mapper.Map <BL.AcademicTitle>(value); var id = _service.SaveAsync(entity); return(Ok(id)); } catch (Exception) { return(BadRequest()); } }
public void CreateAcademicTitle(AcademicTitleDTO academicTitleDTO) { if (academicTitleDTO == null) { throw new ValidationException("Введите данные", ""); } AcademicTitle academicTitle = new AcademicTitle { Title = academicTitleDTO.Title }; Database.AcademicTitles.Create(academicTitle); Database.Save(); }
/// <summary> /// 属性赋值构造函数 /// </summary> /// <param name="name">教材名称</param> /// <param name="author">作者</param> /// <param name="title">作者职称</param> /// <param name="pressname">出版社</param> /// <param name="belonging">教材类别</param> /// <param name="attribute">教材属性</param> /// <param name="wordcount">字数</param> public _BookInformation( string name, string author, AcademicTitle title, string pressname, Category belonging, Property attribute ) { Name = name; Author = author; AuthorTitle = title; PublishingCompany = pressname; Belonging = belonging; Attr = attribute; buildRawData(); }
public async Task <LecturalDTO> UpdateLecturalAsync(Guid id, LecturalDTO lecturalDTO) { var lectural = await _context.Lectural.Where(c => c.id == id) .Include(c => c.Position) .Include(c => c.MilitaryRank) .Include(c => c.AcademicTitle) .Include(c => c.AcademicDegree) .FirstOrDefaultAsync(); if (lectural == null || lectural.id != id) { return(null); } lectural.id = lecturalDTO.id; lectural.firstName = lecturalDTO.firstName; lectural.lastName = lecturalDTO.lastName; lectural.middleName = lecturalDTO.middleName; lectural.birthDay = lecturalDTO.birthDay; lectural.pathPhotoSmall = lecturalDTO.pathPhotoSmall; lectural.pathPhotoBig = lecturalDTO.pathPhotoBig; lectural.serialAndNumderMilitaryDocs = lecturalDTO.serialAndNumderMilitaryDocs; lectural.serialAndNumderCivilyDocs = lecturalDTO.serialAndNumderCivilyDocs; lectural.dateOfStartService = lecturalDTO.dateOfStartService; lectural.isMarried = lecturalDTO.isMarried; lectural.countOfChildren = lecturalDTO.countOfChildren; lectural.info = lecturalDTO.info; if (lectural.AcademicDegree != null) { if (lectural.AcademicDegree.name != lecturalDTO.AcademicDegree) { AcademicDegree academicDegree = _context.AcademicDegree.Where(c => c.name == lecturalDTO.AcademicDegree).FirstOrDefault(); lectural.AcademicDegree = academicDegree; } } else { AcademicDegree academicDegree = _context.AcademicDegree.Where(c => c.name == lecturalDTO.AcademicDegree).FirstOrDefault(); lectural.AcademicDegree = academicDegree; } if (lectural.AcademicTitle != null) { if (lectural.AcademicTitle.name != lecturalDTO.AcademicTitle) { AcademicTitle academicTitle = _context.AcademicTitle.Where(c => c.name == lecturalDTO.AcademicTitle).FirstOrDefault(); lectural.AcademicTitle = academicTitle; } } else { AcademicTitle academicTitle = _context.AcademicTitle.Where(c => c.name == lecturalDTO.AcademicTitle).FirstOrDefault(); lectural.AcademicTitle = academicTitle; } if (lectural.Position != null) { if (lectural.Position.name != lecturalDTO.Position) { Position position = _context.Position.Where(c => c.name == lecturalDTO.Position).FirstOrDefault(); lectural.Position = position; } } else { Position position = _context.Position.Where(c => c.name == lecturalDTO.Position).FirstOrDefault(); lectural.Position = position; } if (lectural.MilitaryRank != null) { if (lectural.MilitaryRank.name != lecturalDTO.MilitaryRank) { MilitaryRank militaryRank = _context.MilitaryRank.Where(c => c.name == lecturalDTO.MilitaryRank).FirstOrDefault(); lectural.MilitaryRank = militaryRank; } } else { MilitaryRank militaryRank = _context.MilitaryRank.Where(c => c.name == lecturalDTO.MilitaryRank).FirstOrDefault(); lectural.MilitaryRank = militaryRank; } _context.Entry(lectural).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(lecturalDTO); } catch (DbUpdateConcurrencyException) { if (!LecturalExists(id)) { return(null); } else { throw; } } }
private void MapForUpdateentity(AcademicTitle entity, DA.AcademicTitle daEntity) { daEntity.Id = entity.Id; }