???????????????ASP.NET Core?б?д???????
???????????? ???????[ 2016/5/23 13:24:10 ] ??????????????????? .NET
????? 2 ??????е???????
public RsvpResult AddRsvp(string name?? string email?? DateTime currentDateTime)
{
if (currentDateTime > RsvpDeadlineDateTime())
{
return new RsvpResult("Failed - Past deadline.");
}
var rsvp = new Rsvp()
{
DateCreated = currentDateTime??
EmailAddress = email??
Name = name
};
if (MaxAttendees.HasValue)
{
if (Rsvps.Count(r => !r.IsWaitlist) >= MaxAttendees.Value)
{
rsvp.IsWaitlist = true;
Rsvps.Add(rsvp);
return new RsvpResult("Waitlist");
}
}
Rsvps.Add(rsvp);
return new RsvpResult("Success");
}
??????????????????????????????????????? API ?????????С??????????????????????????????????????????????????е???????????????????????·?????????
?????????????
?????????????????????? ModelState ?????????Ч??????????????????????????д???????????????ó????У?????????ò??????????????????е????????
????[HttpPost]
????public IActionResult AddRsvp([FromBody]RsvpRequest rsvpRequest)
????{
????if (!ModelState.IsValid)
????{
????return HttpBadRequest(ModelState);
????}
??????? ModelState ??Ч?????????????????????????????????????????? Dinner ????????????????????? ID ?? Dinner ????????????“δ???”?????
????var dinner = _dinnerRepository.GetById(rsvpRequest.DinnerId);
????if (dinner == null)
????{
????return HttpNotFound("Dinner not found.");
????}
???????????Щ???????????????????????????????и????????????????????? Dinner ????? AddRsvp ????????????? OK ???????????????????????????????£?? dinner ??????? RSVP ???????
????var result = dinner.AddRsvp(rsvpRequest.Name??
????rsvpRequest.Email??
????_systemClock.Now);
????_dinnerRepository.Update(dinner);
????return Ok(result);
????}
??????????????? Dinner ?????????????????????????????????????????????????У???? currentDateTime ???????? _systemClock.Now????????? DI ?????????Σ???????????????????????????
?????????????????????????? DI ????????壬?????????????? ASP.NET ???????????????????????????乹?????????????κ??????????_systemClock ?????? IDateTime ????Σ???輸?д???????????????Ρ?
????public interface IDateTime
????{
????DateTime Now { get; }
????}
????public class MachineClockDateTime : IDateTime
????{
????public DateTime Now { get { return System.DateTime.Now; } }
????}
???????????????????? ASP.NET ???????????????? IDateTime ??????? MachineClockDateTime????????????? Startup ??? ConfigureServices ????????????????£??????κζ????????????Ч??????????????????????? MachineClockDateTime ?????????????????ó???
????services.AddSingleton<IDateTime?? MachineClockDateTime>();
???????????????????????????? RSVP ???????????????????????????????????????????????????? Dinner.AddRsvp ????????????????????????????????????????????????????????ж?β??????????????????Э??????????????????????????????????
????????????
??????????????????????? Dinner ?? DinnersController ??????????????????????????????????????“?μ?”?????????????????????????????????????????е?????????????????ó?????????????????????“?1?????????”???1??????? docs.asp.net ??????й? ASP.NET Core ????????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
?????????????????(java .net ?????).Net?й???????????Asp.net MVC??ζ???????????????????????Trim????Asp.Net WebForm????????????.Net??????????С????asp.net ???????????.Net??????????????????Linux???Jexus?й?Asp.Net Core??ó???asp.net??????????????ASP.NET???????JSON?????????????????? .NET ?? Java ???? IT ???.Net??Ч???????????????ù???ASP.NET MVC???????????Щ?£?.NET???????????????????????.net???????????????Asp.net Core MVC?????Session
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????