public IActionResult AddLecturer([FromBody] Lecturer lecturer) { var result = _lecturerService.AddLecturer(lecturer); if (result.IsSucessful) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <ActionResult <LecturerDto> > CreateLecturer(LecturerDto lecturer) { try { if (lecturer == null) { return(BadRequest()); } return(await _lecturerService.AddLecturer(lecturer)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorRetrievingDataFromDataBase)); } }
public async Task <ActionResult> CreateLec(CreateLec createLec, HttpPostedFileBase uploadImage) { createLec.departments = departmentService.GetDepartments().ToList(); if (uploadImage == null) { ModelState.AddModelError("Image", "Add image"); } if (ModelState.IsValid) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } createLec.Image = imageData; var user = new ApplicationUser { UserName = createLec.FirstName + " " + createLec.SecondName, Email = createLec.LecturerEmail }; var result = await UserManager.CreateAsync(user, createLec.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(user.Id, "lecturer"); lecturerService.AddLecturer(new BLL.DTOModels.LecturerDTO { FirstName = createLec.FirstName, SecondName = createLec.SecondName, LecturerEmail = createLec.LecturerEmail, Image = createLec.Image, ImageName = createLec.FirstName + " " + createLec.SecondName, Information = createLec.Information }, createLec.SelectedDepId); return(Redirect("/Manage/Index")); } AddErrors(result); } return(View(createLec)); }
public async Task <IActionResult> Insert(LecturerAddModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dto = _mapper.Map <LecturerDto>(model); try { int id = await _service.AddLecturer(dto); return(CreatedAtRoute("Lecture Get", new { Id = id }, new LecturerModel(id, model.FullName, model.Email, Array.Empty <int>()))); } catch (IncorrectIdException e) { _logger.LogWarning(e, "It seems, validation does not cover some errors."); return(BadRequest(e.Message)); } }
public void Add(LecturerContract lecturer) { _lecturerService.AddLecturer(lecturer.ToEntity()); }