public async Task <IActionResult> CreateFaculty([FromBody] SaveFacultyResource facultyResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var faculty = mapper.Map <SaveFacultyResource, Faculty>(facultyResource); var nameExist = await repository.FacultyNameExist(faculty); if (nameExist != null) { return(Conflict("Faculty name already exists")); } repository.Add(faculty); await unitOfWork.CompleteAsync(); faculty = await repository.GetFaculty(faculty.Id); var result = mapper.Map <Faculty, FacultyResource>(faculty); return(Ok(result)); }
public FacultyDTO Add(FacultyDTO faculty) { FACULTY facToAdd, addedFac; FacultyDTO retVal; retVal = null; if (CheckHelper.IsFilled(faculty)) { try { facToAdd = transformer.TransformFromDTO(-1, faculty); addedFac = facultyRepository.Add(facToAdd); if (CheckHelper.IsFilled(addedFac)) { addedFac.UNIVERSITY = uniRepository.GetById(faculty.UniversityId); retVal = transformer.TransformToDTO(addedFac); } } catch (Exception) { } } return(retVal); }
public async Task <FacultyModel> Add(UpsertFacultyModel model) { var faculty = new Faculty(model.Name); await repository.Add(faculty); await repository.SaveChanges(); return(mapper.Map <FacultyModel>(faculty)); }
public async Task <ActionResult> Add([Bind(Include = "UniversityId, Name")] Faculty faculty) { if (ModelState.IsValid) { _facultyRepository.Add(faculty); await _facultyRepository.Commit(); return(RedirectToAction("Index", new { universityId = faculty.UniversityId })); } return(View(faculty)); }
public async Task <ActionResult <Faculty> > Create(Faculty value) { //Faculty obj = new Faculty(value); _Faculty.Add(value); // it will be null //var testFaculty = await _Faculty.GetById(value.); // If everything is ok then: await _uow.Commit(); // The product will be added only after commit // testProduct = await _productRepository.GetById(product.Id); return(RedirectToAction("Index")); }
public async Task <int> AddFaculty(Faculty faculty) { return(await _facultyRepository.Add(faculty)); }
public Faculty Add(Faculty entity) { return(_facultyRepository.Add(entity)); }
public int AddFaculty(Faculty _faculty) { _faculty.CreatedDate = System.DateTime.Now; return(_facultyRepository.Add(_faculty).FacultyID); }
public async Task Create(Faculty faculty) { await _facultyRepository.Add(faculty); }