public void Add(Major major) { ValidateMajor(major); ValidateDuplicatedMajor(major); _majorRepository.Add(major); }
public async Task <IActionResult> CreateMajor([FromBody] SaveMajorResource majorResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var major = mapper.Map <SaveMajorResource, Major>(majorResource); var nameExist = await repository.MajorNameExist(major); if (nameExist != null) { return(Conflict("Major name already exists")); } repository.Add(major); await unitOfWork.CompleteAsync(); major = await repository.GetMajor(major.Id); var result = mapper.Map <Major, MajorResource>(major); return(Ok(result)); }