public AddEditPromptModel(CommonUtils.Operation operation, int itemId) { CompositionInitializer.SatisfyImports(this); OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true); if (operation == CommonUtils.Operation.Add) { var groupId = itemId; mPrompt = new Prompt(); mPrompt.PromptGroupId = groupId; } else if (operation == CommonUtils.Operation.Update) { var promptId = itemId; CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetPromptCompleted += (s1, e1) => { mPrompt = e1.Result; if (DataLoaded != null) { mPrompt = e1.Result; DataLoaded(); } }; cmsWebServiceClient.GetPromptAsync(promptId); } }
private void OkButtonHander(object parameter) { if (CanExecuteOkButtonHandler(parameter)) { if (AreAllValid()) { CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.SavePromptCompleted += (s1, e1) => { View.SavedPrompt = e1.Result.EntityResult; mPrompt = e1.Result.EntityResult; View.DialogResult = true; }; cmsWebServiceClient.SavePromptAsync(mPrompt); } } }
public DbOperationResult<Prompt> SavePrompt(Prompt prompt) { var result = new DbOperationResult<Prompt>(); try { using (var cee = new CmsEntities()) { Prompt originalObject = (from x in cee.Prompts where x.Id == prompt.Id select x).FirstOrDefault(); if (originalObject == null) { cee.Prompts.Add(prompt); cee.SaveChanges(); result.EntityResult = prompt; } else { originalObject.Name = prompt.Name; originalObject.Description = prompt.Description; originalObject.Ordinal = prompt.Ordinal; cee.SaveChanges(); result.EntityResult = originalObject; } } } catch (Exception ex) { return BuildOperationalErrorResults<Prompt>(ex); } return result; }