private void DataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow; if (row == null) { return; } var item = (sender as DataGrid)?.SelectedItem as ThemeEditorViewmodel.ThemeEditorDV; if (item == null) { return; } var line = SourceEdit.LineFromPosition(SourceEdit.CurrentPosition); string sep = " "; string ind = "\t\t"; for (int i = line; i >= 0; i--) { var txt = SourceEdit.Lines[i].Text.ToLower(); if (txt.Trim().StartsWith("<property ")) { var match = Regex.Match(txt, @"^(?<ind>\s+)<property\s+name=""(?<nam>[^""]+)""(?<sep>\s+)value=.*$"); if (match.Success) { var seplen = match.Groups["nam"].Value.Length + match.Groups["sep"].Value.Length - item.Key.Length; if (seplen < 1) { seplen = 1; } sep = new string(' ', seplen); ind = match.Groups["ind"].Value; } break; } } var str = $"\r\n{ind}<property name=\"{item.Key}\"{sep}value=\"{item.Default}\" />"; SourceEdit.InsertText(SourceEdit.CurrentPosition, str); SourceEdit.CurrentPosition += str.Length; SourceEdit.SelectionStart = SourceEdit.CurrentPosition; SourceEdit.SelectionEnd = SourceEdit.CurrentPosition; }
/// <summary> /// You can update the information on a source /// </summary> /// <param name="source"></param> /// <returns>200 ok</returns> public IHttpActionResult Put(SourceEdit source) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateSourceService(); if (!service.UpdateSource(source)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateSource(SourceEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Sources .Single(e => e.SourceId == model.SourceId); entity.SourceId = model.SourceId; entity.SourceName = model.SourceName; entity.SourceOrigin = model.SourceOrigin; return(ctx.SaveChanges() == 1); } }
//___________________Edit-Update____________ public bool UpdateSource(SourceEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Sources .Single(e => e.SourceId == model.SourceId); entity.Name = model.Name; entity.WebSite = model.WebSite; entity.ShowOrLocation = model.ShowOrLocation; entity.Address = model.Address; entity.City = model.City; entity.State = model.State; entity.ZipCode = model.ZipCode; entity.Note = model.Note; return(ctx.SaveChanges() == 1); } }
//GET: Source/Edit/{id} public ActionResult Edit(int id) { var service = new SourceService(); var detail = service.GetSourceById(id); var model = new SourceEdit { SourceId = detail.SourceId, Name = detail.Name, WebSite = detail.WebSite, ShowOrLocation = detail.ShowOrLocation, Address = detail.Address, City = detail.City, State = detail.State, ZipCode = detail.ZipCode, Note = detail.Note }; return(View(model)); }
public ActionResult Edit(int id, SourceEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SourceId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new SourceService(); if (service.UpdateSource(model)) { TempData["SaveResult"] = "Your source was updated."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Your source could not be updated."); return(View(model)); }