public async Task <IActionResult> Edit(long?id, [FromBody] CreateInputModel model) //EditとCreateで項目が同じなので、入力モデルを使いまわし { //データの入力チェック if (!ModelState.IsValid || !id.HasValue) { return(JsonBadRequest("Invalid inputs.")); } //データの存在チェック var storage = await tenantRepository.GetStorageForUpdateAsync(id.Value); if (storage == null) { return(JsonNotFound($"Storage ID {id.Value} is not found.")); } storage.Name = model.Name; storage.ServerAddress = model.ServerUrl; storage.AccessKey = model.AccessKey; storage.SecretKey = model.SecretKey; storage.NfsServer = model.NfsServer; storage.NfsRoot = model.NfsRoot; tenantRepository.UpdateStorage(storage); unitOfWork.Commit(); tenantRepository.Refresh(); return(JsonOK(new IndexOutputModel(storage))); }
public async Task CreateEventCorrect() { var courseId = Guid.NewGuid().ToString(); var studentId = Guid.NewGuid().ToString(); var inputModel = new CreateInputModel { Name = "Test", Date = "12-03-2020", CourseId = courseId, }; var secondModel = new CreateInputModel { Name = "Test1", Date = "12-03-2020", CourseId = courseId, }; await this.service.CreateEventAsync(studentId, inputModel); await this.service.CreateEventAsync(studentId, secondModel); var count = this.service.GetAllEvents().Count(); Assert.NotNull(inputModel); Assert.NotNull(secondModel); Assert.Equal(2, count); }
public HttpResponse Create(CreateInputModel model) { var name = model.Name.ToLower(); var points = model.Points; bool isProblemExist = problemService.IsProblemExist(name); if (!IsUserSignIn()) { return(Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(name) || 5 > name.Length || name.Length > 20 || isProblemExist) { return(Error("The name should be between 5 and 20 charachters long.")); } if (50 > points || points > 300) { return(Error("The points should be a number between 50 and 300 .")); } problemService.AddProblem(name, points); return(Redirect("/")); }
public HttpResponse Create(CreateInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (input.Name.Length < 4 || input.Name.Length > 20) { return(this.Error("Name must be at least 4 characters and most 20!")); } if (!input.Link.StartsWith("http")) { return(this.Error("Invalid link.")); } if (input.Price < 0) { return(this.Error("Price should be a positive number")); } this.tracksService.Create(input.AlbumId, input.Name, input.Link, input.Price); return(this.Redirect("/Albums/Details?id=" + input.AlbumId)); }
public async Task <IActionResult> Create(CreateInputModel input) { Status result = await _postService.Create(input.Title, input.Description, DateTime.UtcNow, input.AuthorId, input.AuthorName); if (result == Status.Ok) { return(Ok(new Response { Status = result, Error = "" })); } else if (result == Status.InvalidData) { return(BadRequest(new Response { Status = result, Error = "" })); } else { return(StatusCode(500, (new Response { Status = result, Error = "" }))); } }
public async Task <IActionResult> Create(CreateInputModel input) { Status result = await _answerService.Create(input.Text, DateTime.UtcNow, input.AuthorId, input.AuthorName, input.PostId, input.AnswerId); if (result == Status.Ok) { return(Ok(new Response { Status = result, Error = "" })); } else if (result == Status.InvalidData) { return(BadRequest(new Response { Status = result, Error = "" })); } else { return(StatusCode(500, new Response { Status = result, Error = "" })); } }
public IActionResult Create(CreateInputModel model) { if (!this.ModelState.IsValid) { return(BadRequest()); } var category = this.categories.Get().Where(t => t.Name == model.Name || t.Acronym == model.Acronym).FirstOrDefault(); if (category == null) { var newCategory = new Category() { Name = model.Name, Acronym = model.Acronym, Order = model.Order, Active = true, Description = model.Description, }; this.categories.Create(newCategory); } return(this.RedirectToAction("Index", "Category")); }
public HttpResponse Register(CreateInputModel inputModel) { if (inputModel.Username.Length < 5 || inputModel.Username.Length > 20) { return(this.Redirect("/Users/Register")); } if (inputModel.Password.Length < 6 || inputModel.Password.Length > 20) { return(this.Redirect("/Users/Register")); } if (string.IsNullOrWhiteSpace(inputModel.Email)) { return(this.Redirect("/Users/Register")); } if (inputModel.Password != inputModel.ConfirmPassword) { return(this.Redirect("/Users/Register")); } this.usersService.Register(inputModel.Username, inputModel.Email, inputModel.Password); return(this.Redirect("/Users/Login")); }
// GET: Events/Create public IActionResult Create() { createInputModel = new CreateInputModel(); createInputModel.Flight = new Flight(); createInputModel.Offers = new List <OfferInput>(); createInputModel.Airplanes = _context.Airplanes.ToList(); //_context.Offers.Where(x => x.Flight.CompanyId == user.ManagingCompanyId).ToList().ForEach(x => createInputModel.Offers.Add(new OfferInput() { offer = x, selected = false })); _context.Offers.Where(x => x.CompanyId == _userManager.GetUserAsync(User).Result.ManagingCompanyId).ToList().ForEach(x => createInputModel.Offers.Add(new OfferInput() { offer = x, selected = false })); ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Description"); ViewData["RouteId"] = new SelectList(_context.Routes, "RouteId", "RouteId"); List <SelectListItem> selectListItems = new List <SelectListItem>(); selectListItems.Add(new SelectListItem() { Value = "null", Text = "Select an Airplane" }); foreach (var item in _context.Airplanes.ToList()) { selectListItems.Add(new SelectListItem(item.Id + "Business Row/Col" + item.BusinessRowNo + "/" + item.BusinessColumnNo + ". Economy Row/Col: " + item.EconomyRowNo + "/" + item.EconomyColumnNo, item.Id)); } ViewData["AirplaneId"] = new SelectList(selectListItems, "Value", "Text"); return(View(createInputModel)); }
public HttpResponse Create(CreateInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.Name) || input.Name.Length > 20 || input.Name.Length < 4) { return(this.Error("Name should be between 4 and 20 characters!")); } if (string.IsNullOrEmpty(input.Link)) { return(this.Error("Link should be valid!")); } if (input.Price < 0) { return(this.Error("Price should be positive!")); } this.tracksService.Create(input.AlbumId, input.Name, input.Link, input.Price); return(this.Redirect("/Albums/Details?id=" + input.AlbumId)); }
public IActionResult Create() { var model = new CreateInputModel(); model.Description = "initial value"; return(this.View(model)); }
public async Task <IActionResult> Create([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } if (string.IsNullOrWhiteSpace(model.Name)) { //名前に空文字は許可しない return(JsonBadRequest($"A name of Preprocessing is NOT allowed to set empty string.")); } if (model.GitModel != null && model.GitModel.IsValid() == false) { return(JsonBadRequest($"The input about Git is not valid.")); } Preprocess preprocessing = new Preprocess(); var errorResult = await SetPreprocessDetailsAsync(preprocessing, model); if (errorResult != null) { return(errorResult); } preprocessRepository.Add(preprocessing); unitOfWork.Commit(); return(JsonCreated(new IndexOutputModel(preprocessing))); }
public IActionResult Create(CreateInputModel model) { if (!this.ModelState.IsValid) { return(BadRequest()); } var tag = model.IsProductTag ? this.tags.GetProductTag().Any(t => t.Name == model.Name || t.Acronym == model.Acronym) : this.tags.GetPostTag().Any(t => t.Name == model.Name || t.Acronym == model.Acronym); if (!tag) { if (model.IsProductTag) { var newTag = new ProductTag() { Name = model.Name, Acronym = model.Acronym, Active = true }; this.tags.Create(newTag); } else { var newTag = new PostTag() { Name = model.Name, Acronym = model.Acronym, Active = true }; this.tags.Create(newTag); } } return(this.RedirectToAction("Index", "Tag")); }
public ActionResult Create(CreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var feedback = new Feedback() { Content = this.sanitizer.Sanitize(input.Content), PostId = Convert.ToInt32(TempData["PostId"]) }; if (this.User.Identity.IsAuthenticated) { feedback.AuthorId = this.User.Identity.GetUserId(); } this.feedbacks.Add(feedback); this.feedbacks.SaveChanges(); this.TempData["Notification"] = "Thank you for your feedback!"; return(this.Redirect(Request.UrlReferrer.ToString())); }
public async Task <IActionResult> Edit(long?id, [FromBody] CreateInputModel model) //EditとCreateで項目が同じなので、入力モデルを使いまわし { //データの入力チェック if (!ModelState.IsValid || !id.HasValue) { return(JsonBadRequest("Invalid inputs.")); } //データの存在チェック var git = await gitRepository.GetByIdAsync(id.Value); if (git == null) { return(JsonNotFound($"Git ID {id.Value} is not found.")); } git.Name = model.Name; git.ServiceType = model.ServiceType.Value; git.ApiUrl = model.ApiUrl; git.RepositoryUrl = model.RepositoryUrl; gitRepository.Update(git); unitOfWork.Commit(); return(JsonOK(new IndexOutputModel(git))); }
public IActionResult Create([FromBody] CreateInputModel model) { // データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } // 同じ名前のレジストリは登録できないので、確認する var registry = registryRepository.GetRegistryAll().FirstOrDefault(r => r.Name == model.Name); if (registry != null) { return(JsonConflict($"Registry {model.Name} already exists.")); } registry = new Registry() { Name = model.Name, Host = model.Host, PortNo = model.PortNo.Value, ServiceType = model.ServiceType.Value, ProjectName = model.ProjectName, ApiUrl = model.ApiUrl, RegistryUrl = model.RegistryUrl }; registryRepository.Add(registry); unitOfWork.Commit(); var result = new IndexOutputModel(registry); return(JsonOK(result)); }
public async Task <IActionResult> CreateDataSet([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } DataSet dataSet = new DataSet() { Name = model.Name, Memo = model.Memo, IsLocked = false }; dataSetRepository.Add(dataSet); if (model.Entries == null) { unitOfWork.Commit(); return(JsonOK(new IndexOutputModel(dataSet))); } return(await InsertDataSetEntryAsync(dataSet, model.Entries, true)); }
public HttpResponse Create(CreateInputModel inputModel) { if (!IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (inputModel.Name.Length <= 4 || inputModel.Name.Length >= 20) { return(this.Redirect("/Tracks/Create")); } if (string.IsNullOrWhiteSpace(inputModel.Link)) { return(this.Redirect("/Tracks/Create")); } if (!inputModel.Link.StartsWith("http")) { return(this.Redirect("/Tracks/Create")); } if (inputModel.Price < 0.00M) { return(this.Redirect("/Tracks/Create")); } return(this.View()); }
public IActionResult Create([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } Storage storage = new Storage() { Name = model.Name, ServerAddress = model.ServerUrl, AccessKey = model.AccessKey, SecretKey = model.SecretKey, NfsServer = model.NfsServer, NfsRoot = model.NfsRoot }; tenantRepository.AddStorage(storage); unitOfWork.Commit(); tenantRepository.Refresh(); var result = new IndexOutputModel(storage); return(JsonOK(result)); }
public IActionResult Create([FromBody] CreateInputModel model) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } if (string.IsNullOrWhiteSpace(model.Name)) { //名前に空文字は許可しない return(JsonBadRequest($"A name of Data is NOT allowed to set empty string.")); } // データの登録 Data newData = new Data() { // 名前の前後の空白文字を除去して設定する。 Name = model.Name.Trim(), Memo = model.Memo, }; //タグの登録 if (model.Tags != null && model.Tags.Count() > 0) { tagLogic.Create(newData, model.Tags); } dataRepository.Add(newData); // DBへのコミット unitOfWork.Commit(); return(JsonCreated(new IndexOutputModel(newData))); }
public async Task CreateAsyncMethodAddMiniLeague() { var list = new List <MiniLigue>(); var miniLeagueRepo = new Mock <IDeletableEntityRepository <MiniLigue> >(); miniLeagueRepo.Setup(x => x.All()).Returns(list.AsQueryable()); miniLeagueRepo.Setup(x => x.AddAsync(It.IsAny <MiniLigue>())).Callback( (MiniLigue league) => list.Add(league)); var miniUserRepo = new Mock <IDeletableEntityRepository <MiniLigueUser> >(); var service = new MiniLeaguesService(miniLeagueRepo.Object, miniUserRepo.Object); var model = new CreateInputModel { Name = "moqtaLiga", Password = "******", }; await service.CreateAsync(model, "abc"); var league = list.First(); var name = league.Name; var password = league.Password; var creatorId = league.CreatorId; Assert.Equal(1, list.Count); Assert.Equal(ComputeHash(model.Password), password); Assert.Equal(model.Name, name); Assert.Equal("abc", creatorId); }
public IActionResult Create([FromBody] CreateInputModel model) { if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } if (model.AccessLevel != TemplateAccessLevel.Disabled && model.AccessLevel != TemplateAccessLevel.Private && model.AccessLevel != TemplateAccessLevel.Public) { return(JsonBadRequest("Invalid access level")); } var template = new Template { Name = model.Name, Memo = model.Memo, LatestVersion = 0, AccessLevel = model.AccessLevel, CreaterUserId = CurrentUserInfo.Id, CreaterTenantId = CurrentUserInfo.SelectedTenant.Id, }; templateRepository.Add(template); unitOfWork.Commit(); return(JsonCreated(new IndexOutputModel(template))); }
public HttpResponse Create(CreateInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (input.Name.Length < 4 || input.Name.Length > 20) { return(this.Error("Track name should be between 4 and 20 charcters!")); } if (!input.Link.StartsWith("http")) { return(this.Error("Invalid Link!")); } if (input.Price < 0) { return(this.Error("Price should be positive number!")); } this.tracksService.Create(input.AlbumId, input.Name, input.Link, input.Price); return(this.Redirect("/Albums/Details?id=" + input.AlbumId)); }
public HttpResponse Create(CreateInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.Name)) { return(this.Error("Name is required!")); } if (input.Name.Length < 3 || input.Name.Length > 10) { return(this.Error("Name must be between 3 and 10 characters long!")); } if (string.IsNullOrEmpty(input.RepositoryType)) { return(this.Error("Type must be selected!")); } var userId = this.GetUserId(); this.repositoriesService.CreateRepository(input.Name, input.RepositoryType, userId); return(this.Redirect("/Repositories/All")); }
public HttpResponse Create(CreateInputModel input) { if (this.IsUserLoggedIn()) { if (input.Name.Length < 4 || input.Name.Length > 20) { return(this.Error("Track name should be between 4 and 20 characters long.")); } if (!input.Link.StartsWith("http")) { return(this.Error("Please enter a valid link ")); } if (input.Price < 0) { return(this.Error("Price should be a positive number")); } this.service.CreateTrack(input.AlbumId, input.Name, input.Link, input.Price); return(this.Redirect($"/Album/Details?id={input.AlbumId}")); } return(this.Redirect("/Users/Login")); }
public async Task <IActionResult> Create([FromBody] CreateInputModel model, [FromServices] ITenantRepository tenantRepository) { //データの入力チェック if (!ModelState.IsValid) { return(JsonBadRequest("Invalid inputs.")); } //同じ名前のノードは登録できないので、確認する Node node = await nodeRepository.GetByNameAsync(model.Name); if (node != null) { return(JsonConflict($"Node {model.Name} already exists: ID = {node.Id}")); } node = new Node() { Name = model.Name, Memo = model.Memo, Partition = model.Partition, AccessLevel = model.AccessLevel == null ? NodeAccessLevel.Disabled : model.AccessLevel.Value, TensorBoardEnabled = model.TensorBoardEnabled }; if (node.AccessLevel != NodeAccessLevel.Disabled) { //アクセスレベルがDisable以外であれば、k8sとの同期を行う //ノードが存在しない場合を考慮し、もし失敗しても気にせず更新処理を続ける await clusterManagementLogic.UpdatePartitionLabelAsync(node.Name, node.Partition); if (node.TensorBoardEnabled) { await clusterManagementLogic.UpdateTensorBoardEnabledLabelAsync(node.Name, true); } if (node.AccessLevel == NodeAccessLevel.Private) { //テナントをアサイン if (model.AssignedTenantIds != null) { foreach (long tenantId in model.AssignedTenantIds) { if (tenantRepository.Get(tenantId) == null) { return(JsonNotFound($"Tenant ID {tenantId} is not found.")); } } nodeRepository.AssignTenants(node, model.AssignedTenantIds, true); } } } nodeRepository.Add(node); unitOfWork.Commit(); return(JsonCreated(new IndexOutputModel(node))); }
public ActionResult Register(CreateInputModel createInputModel) { if (ModelState.IsValid) { var accountCreated = _applicantService.CreateApplicant(createInputModel); } return(View(createInputModel)); }
public IActionResult Create(CreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } return(this.Json(input)); }
public IActionResult Create(string homeworkId) { var inputModel = new CreateInputModel { HomeworkId = homeworkId, }; return(this.View(inputModel)); }
public IActionResult Create(string courseId) { var inputModel = new CreateInputModel { CourseId = courseId, }; return(this.View(inputModel)); }