public async Task <IActionResult> Post([FromBody] SaveSchoolResources schoolR) { // validate model if (!ModelState.IsValid) { return(BadRequest()); } // convert from modelresource to datamodel var model = _mapper.Map <SaveSchoolResources, School>(schoolR); // save into th database _schoolRepository.Add(model); // save to database await _unitOfWork.CompleteAsync(); // get the saved school var school = await _schoolRepository.GetSchool(model.Id); // map to resources var schoolresources = _mapper.Map <School, SaveSchoolResources>(school); return(Ok(schoolresources)); }
public async Task <ActionResult> CreateTeacher([FromBody] CreateTeacherViewModel model) { if (ModelState.IsValid) { // creating the school var school = new School(model.SchoolName, GetRandomString(6)); _schoolRepository.Add(school); await _schoolRepository.SaveChanges(); // creating teacher consisting of his school var user = _authenticationManager.CreateApplicationUserObject(model.Email, model.Username, model.Password); user.School = await _schoolRepository.GetByName(model.SchoolName); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { user = _userManager.Users.SingleOrDefault(u => u.Id == user.Id); if (user.School == null) { return(Ok( new { Message = "Something went wrong when creating your account." })); } await _userManager.AddToRoleAsync(user, "Teacher"); var claim = await CreateClaims(user); //Todo kunnen van CreateClaims in List werken idpv array zodat men niet hoeft de array naar list om te zetten // en in addschoolclaim hoeft men dan geen returnwaarde te geven (want het Adden vd claim is op reference van de lijst) claim = _authenticationManager.AddClaim(claim.ToList(), "school", school.Id.ToString()).ToArray(); var token = GetToken(claim); return(Ok( new { // Username = user.UserName, // Token = GetToken(claim) token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo })); } } return(Ok( new { Message = "Error please make sure your details are correct" })); }
public ActionResult Create(School s) { try { schoolRepository.Add(s); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
// Cadastrasr uma nova escola public ICommandResult Handle(CreateSchoolCommand command) { // Valida os dados do command command.Validate(); // Se for invalido, mostrar as notificações if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, SharedMessages.InvalidOperation, command)); } // Preenche o VO document com as informações do command var document = new Document(command.DocumentNumber, command.Type); // Preenche o VO address com as informações do command var address = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.StateName, command.Country, command.ZipCode, command.StateAbbr); // Preenche a entitie com os dados dos VOs e command var school = new Entities.School(command.Name, document, address, command.Phone); // Caso algum deles retorne erro, mostre as notificações AddNotifications(document, address, school); // Checando as notificações if (Invalid) { return(new CommandResult(false, SharedMessages.InvalidOperation, school)); } // Salvando informações if (!_schoolRepository.DocumentExists(command.DocumentNumber)) { _schoolRepository.Add(school); } else { return(new CommandResult(false, SharedMessages.DocumentExists, school)); } _uow.Commit(); // Retornando informações de sucesso e o objeto preenchido return(new CommandResult(true, SharedMessages.SuccedOperation, school)); }
public IActionResult Post([FromBody] SchoolModel school) { if (ModelState.IsValid) { var sc = Mapper.Map <School>(school); sc.Date = DateTime.UtcNow; sc.SchoolId = _schoolRepository.GetMaxId() + 1; _schoolRepository.Add(sc); } var result = _schoolRepository.Fetch(); var results = Mapper.Map <IEnumerable <SchoolModel> >(result); return(new ObjectResult(results)); }
public IActionResult Create(SchoolModel school) { if (ModelState.IsValid) { var sc = Mapper.Map <School>(school); sc.Date = DateTime.UtcNow; sc.SchoolId = _repo.GetMaxId() + 1; _repo.Add(sc); return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, "Please correct the errors!"); return(View(school)); }
public async Task <ActionResult <bool> > create(School SchoolToCreate) { var newschool = new School() { schoolid = SchoolToCreate.schoolid, name = SchoolToCreate.name, address = SchoolToCreate.address, phonenumber = SchoolToCreate.phonenumber, grade = SchoolToCreate.grade }; _schoolRepo.Add(newschool); return(await _schoolRepo.SaveAll()); }
public bool CreateSchool(School school) { bool isSuccess = true; try { schoolRepository.Add(school); this.SaveRecord(); ServiceUtil <School> .WriteActionLog(school.Id, ENUMOperation.CREATE, school); } catch (Exception ex) { isSuccess = false; logger.Error("Error in creating School", ex); } return(isSuccess); }
public IActionResult Post([FromBody] School school) { try { _schoolRepository.Add(school); var Respond = Ok(); response.StatusCode = Respond.StatusCode; response.Message = Constants.Success; return(Ok(response)); } catch (Exception) { var Respond = BadRequest(); response.StatusCode = Respond.StatusCode; response.Message = Constants.Failure; return(BadRequest(response)); } }
// Create public void CreateSchool(School School) { SchoolRepository.Add(School); SaveSchool(); }
public IActionResult Post(School school) { _schoolRepo.Add(school); return(CreatedAtAction("GetSchool", new { id = school.Id }, school)); }