예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }
예제 #5
0
        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"));
        }
예제 #6
0
 public async Task <int> AddFaculty(Faculty faculty)
 {
     return(await _facultyRepository.Add(faculty));
 }
예제 #7
0
 public Faculty Add(Faculty entity)
 {
     return(_facultyRepository.Add(entity));
 }
예제 #8
0
 public int AddFaculty(Faculty _faculty)
 {
     _faculty.CreatedDate = System.DateTime.Now;
     return(_facultyRepository.Add(_faculty).FacultyID);
 }
예제 #9
0
 public async Task Create(Faculty faculty)
 {
     await _facultyRepository.Add(faculty);
 }