public override void Query() { if (controller == null) { return; } if (Id != Guid.Empty) { var result = controller.Query(p => p.Id == Id); if (!result.HasError) { ProjectContract data = result.Result.Single(); BindingFromModel(data, this); if (data.CreateUser != null) { CreateUser = data.CreateUser.UserName; } if (data.PromissoryNoteManagement.Any()) { PromissoryNoteManagement.Clear(); foreach (var row in data.PromissoryNoteManagement) { PromissoryNoteManagementViewModel model = new PromissoryNoteManagementViewModel(); model.DoEvents(); model.SetModel(row); PromissoryNoteManagement.Add(model); } } if (data.ProcessingAtlas.Any()) { ProcessingAtlas.Clear(); foreach (var row in data.ProcessingAtlas.OrderBy(o => o.Order).ToList()) { ProcessingAtlasViewModel model = new ProcessingAtlasViewModel(); model.DoEvents(); model.SetModel(row); ProcessingAtlas.Add(model); } } } } }
public override void SaveModel() { ProjectContract data = new ProjectContract(); CopyToModel(data, this); if (data.CreateUserId == Guid.Empty) { data.CreateUserId = controller.GetCurrentLoginUser().Result.UserId; } if (PromissoryNoteManagement.Any()) { foreach (PromissoryNoteManagementViewModel model in PromissoryNoteManagement) { PromissoryNoteManagement entity = new PromissoryNoteManagement(); CopyToModel(entity, model); entity.ProjectContractId = data.Id; data.PromissoryNoteManagement.Add(entity); } } if (ProcessingAtlas.Any()) { foreach (ProcessingAtlasViewModel model in ProcessingAtlas) { ProcessingAtlas entity = new ProcessingAtlas(); CopyToModel(entity, model); entity.ProjectContractId = data.Id; data.ProcessingAtlas.Add(entity); } } var result = controller.CreateOrUpdate(data); if (result.HasError) { Errors = result.Errors; HasError = result.HasError; } Refresh(); }