public IHttpActionResult AddInstructor([FromBody] GroupInstructorDTO groupInstructor) { var entity = groupInstructorMapper.Map(groupInstructor); instructorService.AddInstructor(entity); return(Ok()); }
public ActionResult Create(Instructor instructor) { try { // TODO: Add insert logic here _service.AddInstructor(instructor); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create([Bind(Include = "Id,InstructorName,InstructorContact")] Instructor instructor) { var validationResult = _instructorService.Validate(instructor); if (!validationResult.Item1) { throw new Exception(validationResult.Item2); } _instructorService.AddInstructor(instructor); return(RedirectToAction("Index")); }
public ActionResult Create(InstructorPerson IPerson) { try { // TODO: Add insert logic here //Department dept = new Department() { // Name = DepartmentName, // Budget = Budget //}; _instructorService.AddInstructor(IPerson); return(RedirectToAction("Index")); } catch { return(View()); } }
public HttpResponseMessage Post([FromBody] InstructorPerson Instructor) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Instructor data is invalid.")); } try { _Instructorservice.AddInstructor(Instructor); var message = Request.CreateResponse(HttpStatusCode.Created, Instructor); message.Headers.Location = new Uri(Url.Link("GetInstructorById", new { id = Instructor.Person.Id })); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Some internal error occurs...")); } }
public async Task <IActionResult> AddInstructor([FromBody] InstructorDTO model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var user = _mapper.Map <UserDTO, User>(model.User); var result = await _userManager.CreateAsync(user, model.User.Password); await _userManager.AddToRoleAsync(user, "instructor"); if (!result.Succeeded) { return(BadRequest("Email already exists!")); } var userAdded = _userManager.FindByNameAsync(user.Email).Result; var newInstructor = new Instructor() { Salary = model.Salary, HireDate = model.HireDate, UserId = userAdded.Id }; _instructorService.AddInstructor(newInstructor, model.Categories); var instructorDTO = _mapper.Map <Instructor, InstructorDTO>(newInstructor); return(Created("", instructorDTO)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }