// GET: YUXING public ActionResult Index() { StudentPrototype student1 = StudentPrototype.CreateTance(); student1.Id = 3; student1.Name = "111";//=new string("111"); //字符串在内存上是不可变得,每一次都是一个new的动作 student1.Class.ClassId = 2; student1.Class.ClassName = "测试"; StudentPrototype student2 = StudentPrototype.CreateTance(); student2.Id = 4; student2.Name = "444"; student2.Class.ClassId = 4; student2.Class.ClassName = "4测试"; StudentPrototype student3 = StudentPrototype.CreateInstanceSerialize(); student3.Id = 6; student3.Name = "666";//=new string("111"); //字符串在内存上是不可变得,每一次都是一个new的动作 student3.Class.ClassId = 6; student3.Class.ClassName = "666"; StudentPrototype student4 = StudentPrototype.CreateInstanceSerialize(); student4.Id = 7; student4.Name = "7"; student4.Class.ClassId = 7; student4.Class.ClassName = "7777"; return(View()); }
public bool ValidateAndSave(StudentPrototype request) { if (!validate(request)) return false; _studentRepo.Save(request.MapFromPrototype()); if (request.CreateNewSchool) { _schoolRepo.Save(new SchoolDto() { Name = request.School }); } return true; }
public bool ValidateAndUpdate(StudentPrototype request) { if (!validate(request)) return false; _studentRepo.WithinUpdateContext(() => { var entity = _studentRepo.Find(e => e.FirstName == request.FirstName && e.LastName == request.LastName && e.Address1 == request.Address1); request.MergeWithPrototype(entity); }); return true; }
public void CopyStudentChangeAddress() { StudentPrototype youngStudent = new StudentPrototype(); youngStudent.Age = 15; youngStudent.Name = "John"; youngStudent._Address.Street = "Street"; StudentPrototype oldStudent = (StudentPrototype)youngStudent.Clone(); oldStudent.Age = 70; oldStudent._Address.Street = "Avenue"; Assert.AreEqual("Street", youngStudent._Address.Street); Assert.AreEqual("Avenue", oldStudent._Address.Street); }
private static bool validate(StudentPrototype request) { request.ValidationErrorMsgs = ""; var valMsgs = new StringBuilder(); string suffix = "should be a numeric value! "; if (request.EnvelopeNumber.IsNullOrEmpty()) valMsgs.AppendLine("Envelope Number is required!"); if (!request.AmountFromEnvelope.IsNumeric()) valMsgs.AppendLine("'Amount from Envelope' " + suffix); if (!request.AmountFromWebsite.IsNumeric()) valMsgs.AppendLine("'Amount from Website' " + suffix); if (!request.MinutesRead.IsNumeric()) valMsgs.AppendLine("'Minutes Read' " + suffix); if (!request.PagesRead.IsNumeric()) valMsgs.AppendLine("'Pages Read' " + suffix); if (!request.ReadingGoal.IsNumeric()) valMsgs.AppendLine("'Reading Goal' " + suffix); if (valMsgs.Length == 0) return true; request.ValidationErrorMsgs = valMsgs.ToString(); return false; }