public ActionResult Edit(int?id = null) { EditProjectSourceModel model = null; int?currentConfigTypeId = null; if (id.HasValue) { var obj = ProjectSourceLogic.Get(id.Value); if (obj != null) { model = ModelConverter.ConvertToEdit(obj); currentConfigTypeId = obj.SourceConfig.Id; } else { this.AddWarning("NoProjectSourceFound", "No ProjectSource was found with that Id. Switching to Create mode."); return(Redirect(Url.ProjectSource_Create())); } } if (model == null) { model = new EditProjectSourceModel(); } var availableTypeItems = ProjectSourceTypeLogic.GetAll() .Select(c => new SelectListItem { Text = c.Name, Value = c.Id.ToString() }); model.AvailableTypes = new SelectList(availableTypeItems, availableTypeItems.FirstOrDefault(a => a.Value == currentConfigTypeId.ToString())); return(View("Edit", model)); }
public ActionResult Edit(EditProjectSourceModel model) { if (!ModelState.IsValid) { return(Redirect(Url.ProjectSource_Edit(model.Id))); } ProjectSourceObj obj; if (!model.Id.HasValue) { obj = ModelConverter.Convert(model); obj.Id = ProjectSourceLogic.Create(obj, CurrentUserName); if (obj.Id == -1) { this.AddError("CreatingProjectSource", "There was an error creating your ProjectSource. If this continues contact support."); return(Redirect(Url.ProjectSource_Create())); } } else { obj = ModelConverter.Convert(model); var success = ProjectSourceLogic.Update(obj, CurrentUserName); if (!success) { this.AddError("UpdatingProjectSource", "There was an error updating your ProjectSource. If this continues contact support."); return(Redirect(Url.ProjectSource_Edit(model.Id.Value))); } } return(Redirect(Url.ProjectSource_Show(obj.Id.Value))); }
internal static ProjectSourceObj Convert(EditProjectSourceModel model) { return(new ProjectSourceObj { Id = model.Id /* * Copy other properties here */ }); }