added create page
This commit is contained in:
Родитель
283976c454
Коммит
faedffea8d
|
@ -1,8 +1,41 @@
|
|||
@page
|
||||
@model RPS.Web.Pages.Backlog.CreateModel
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
|
||||
<h2>Create</h2>
|
||||
|
||||
<h2>Add New Item</h2>
|
||||
|
||||
<form method="post">
|
||||
|
||||
<div class="form-group row">
|
||||
<label asp-for="@Model.Title" class="col-sm-2 col-form-label"></label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" asp-for="@Model.Title" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label asp-for="@Model.Description" class="col-sm-2 col-form-label"></label>
|
||||
<div class="col-sm-10">
|
||||
<textarea asp-for="@Model.Description" class="form-control"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label asp-for="@Model.TypeStr" class="col-sm-2 col-form-label"></label>
|
||||
<div class="col-sm-10">
|
||||
<select asp-for="@Model.TypeStr" asp-items="@Model.ItemTypes" class="form-control"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="offset-sm-2 col-sm-10">
|
||||
<input type="submit" value="Add" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<div>
|
||||
<a href="/Backlog">Back to List</a>
|
||||
</div>
|
||||
|
|
|
@ -1,17 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using RPS.Core.Models.Dto;
|
||||
using RPS.Core.Models.Enums;
|
||||
using RPS.Data;
|
||||
|
||||
namespace RPS.Web.Pages.Backlog
|
||||
{
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private const int CURRENT_USER_ID = 21; //Fake user id for demo
|
||||
|
||||
private readonly IPtItemsRepository rpsItemsRepo;
|
||||
|
||||
private readonly List<ItemTypeEnum> _itemTypes = new List<ItemTypeEnum> { ItemTypeEnum.Bug, ItemTypeEnum.Chore, ItemTypeEnum.Impediment, ItemTypeEnum.PBI };
|
||||
|
||||
[Required, Display(Name = "Title")]
|
||||
[BindProperty]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Display(Name = "Description")]
|
||||
[BindProperty]
|
||||
public string Description { get; set; }
|
||||
|
||||
[Display(Name = "Type")]
|
||||
[BindProperty]
|
||||
public ItemTypeEnum TypeStr { get; set; }
|
||||
|
||||
public IEnumerable<SelectListItem> ItemTypes
|
||||
{
|
||||
get { return new SelectList(_itemTypes, ItemTypeEnum.Bug); }
|
||||
}
|
||||
|
||||
public CreateModel(IPtItemsRepository rpsItemsData)
|
||||
{
|
||||
rpsItemsRepo = rpsItemsData;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
TypeStr = ItemTypeEnum.Bug;
|
||||
}
|
||||
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
var newItem = ToPtNewItem();
|
||||
newItem.UserId = CURRENT_USER_ID;
|
||||
|
||||
rpsItemsRepo.AddNewItem(newItem);
|
||||
|
||||
return RedirectToPage("/Backlog/Items");
|
||||
}
|
||||
|
||||
public PtNewItem ToPtNewItem()
|
||||
{
|
||||
return new PtNewItem
|
||||
{
|
||||
Title = Title,
|
||||
Description = Description,
|
||||
TypeStr = TypeStr
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче