public async Task <ActionResult> Edit([Bind(Include = "Id,Enabled,Name,MvvmTemplateCategoryId,Language,Tags,ViewModel,View")] MvvmTemplate mvvmTemplate) { // Have to retrieve and reassign the ApplicationUserId since it wasn't given // to the client (a security risk). Be sure to use AsNoTracking() so EF doesn't // think we're attaching a dupe on SaveChanges(). var t = db.MvvmTemplates.AsNoTracking().First(template => template.Id == mvvmTemplate.Id); mvvmTemplate.ApplicationUserId = t.ApplicationUserId; if (!AuthorizeTemplateAccess(t)) { return(new HttpUnauthorizedResult()); } if (ModelState.IsValid) { db.Entry(mvvmTemplate).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } var model = new TemplateEditViewModel(mvvmTemplate, db.MvvmTemplateCategories); return(View(model)); }
public ActionResult RegisterTemplate(TemplateEditViewModel model) { if (ModelState.IsValid) { if (model.Regions != null && model.Regions.GroupBy(r => r.Identifier).SelectMany(g => g.Skip(1)).Any()) { Messages.AddError(PagesGlobalization.SaveTemplate_DublicateRegionIdentificator_Message); return(Json(new WireJson { Success = false })); } var response = GetCommand <SaveTemplateCommand>().ExecuteCommand(model); if (response != null) { if (model.Id.HasDefaultValue()) { Messages.AddSuccess(PagesGlobalization.SaveTemplate_CreatedSuccessfully_Message); } return(Json(new WireJson { Success = true, Data = response })); } } return(Json(new WireJson { Success = false })); }
public async Task <ActionResult <TemplateEditRetModel> > Edit(TemplateEditViewModel model) { await using (_dbContext) { var entity = await _dbContext.WorkflowTemplate.FindAsync(model.Code); entity.Name = model.Name; entity.Description = model.Description; entity.ParentCode = model.ParentCode; entity.Visible = model.Visible; entity.IsStepFree = model.IsStepFree; entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid; entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName; entity.ModifiedOn = DateTime.Now; if (!ConfigurationManager.AppSettings.IsTrialVersion) { entity.Status = model.Status; } _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); var response = ResponseModelFactory.CreateInstance; response.SetSuccess(); return(Ok(response)); } }
public ActionResult EditCategory(int id, FormCollection formData) { TemplateEditViewModel model = GetModel(id); // Validate input string CategorysInput = formData["CategorysInput"].Trim(); List <CategoryDto> categorys = new List <CategoryDto>(); if (!string.IsNullOrEmpty(CategorysInput)) { string[] items = CategorysInput.Split(','); foreach (string item in items) { if (!string.IsNullOrWhiteSpace(item)) { categorys.Add(new CategoryDto { CategoryText = item }); } } } if (ModelState.IsValid) { model.Instance.Categorys = categorys; IFacadeUpdateResult <TemplateData> result = Service.SaveTemplateCategorys(model.Instance); if (result.IsSuccessful) { return(RedirectToAction(DetailAction, new { id = id })); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } } return(View(model)); }
public static TemplateEditViewModel ToServiceModel(this SaveLayoutModel model) { var serviceModel = new TemplateEditViewModel(); serviceModel.Version = model.Version; serviceModel.Name = model.Name; serviceModel.Url = model.LayoutPath; serviceModel.PreviewImageUrl = model.PreviewUrl; if (model.Options != null) { serviceModel.Options = model.Options.ToServiceModel(); } if (model.Regions != null) { serviceModel.Regions = model .Regions .Select(r => new TemplateRegionItemViewModel { Description = r.Description, Identifier = r.RegionIdentifier }) .ToList(); } return(serviceModel); }
public async Task <TemplateEditViewModel> GetEditViewTemplate(int templateId) { NotificationTemplateEntityModel template = await Db.NotificationTemplates.FindAsync(templateId); TemplateEditViewModel model = new TemplateEditViewModel(template, User.TimeZoneInfoId); return(model); }
private TemplateEditViewModel GetModel(int templateId) { TemplateEditViewModel model = new TemplateEditViewModel(); model.FolderTree = GetCurrentFolderTree(); model.Instance = Service.GetTemplate(templateId); return(model); }
public async Task <ActionResult> Edit([Bind(Include = "TemplateID,Subject,EmailBody,TextMessage")] TemplateEditViewModel template) { if (ModelState.IsValid) { await lib.UpdateEditViewTemplate(template); return(RedirectToAction("Index")); } return(View(await lib.GetEditViewTemplate(template.TemplateID))); }
// GET: NotificationTemplates/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TemplateEditViewModel template = await lib.GetEditViewTemplate((int)id); if (template == null) { return(HttpNotFound()); } return(View(template)); }
public async Task UpdateEditViewTemplate(TemplateEditViewModel template) { NotificationTemplateEntityModel update = await Db.NotificationTemplates.FindAsync(template.TemplateID); await Db.Entry(update).Reference(r => r.CreatedBy).LoadAsync(); update.EmailBody = template.EmailBody; update.Subject = template.Subject; update.TextMessage = template.TextMessage; update.UpdatedBy = User; update.UpdatedDt = DateTimeOffset.Now; await Db.SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); }
public TemplateEditPage(Template?template) { InitializeComponent(); var types = ServiceLocatorByType <EntryBase> .GetNames(); foreach (var t in types) { TypePicker.Items.Add(t); } BindingContext = ViewModel = new TemplateEditViewModel(template); AssignEntry(ViewModel.Template.Entry); TypePicker.SelectedItem = ViewModel.Template.Entry?.GetType().FullName; loaded = true; }
public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var mvvmTemplate = await db.MvvmTemplates.FindAsync(id); if (!AuthorizeTemplateAccess(mvvmTemplate)) { return(new HttpUnauthorizedResult()); } if (mvvmTemplate == null) { return(HttpNotFound()); } var model = new TemplateEditViewModel(mvvmTemplate, db.MvvmTemplateCategories); return(View(model)); }
public ActionResult RegisterTemplate(TemplateEditViewModel model) { if (ModelState.IsValid) { var viewEngineResult = ViewEngines.Engines.FindView(ControllerContext, model.Url, null); if (viewEngineResult == null || viewEngineResult.View == null) { Messages.AddError(string.Format(PagesGlobalization.SaveTemplate_VirtualPathNotExists_Message, model.Url)); return(Json(new WireJson { Success = false })); } if (model.Regions != null && model.Regions.GroupBy(r => r.Identifier).SelectMany(g => g.Skip(1)).Any()) { Messages.AddError(PagesGlobalization.SaveTemplate_DublicateRegionIdentificator_Message); return(Json(new WireJson { Success = false })); } var response = GetCommand <SaveTemplateCommand>().ExecuteCommand(model); if (response != null) { if (model.Id.HasDefaultValue()) { Messages.AddSuccess(PagesGlobalization.SaveTemplate_CreatedSuccessfully_Message); } return(Json(new WireJson { Success = true, Data = response })); } } return(Json(new WireJson { Success = false })); }
/// <summary> /// Saves the layout. /// </summary> /// <param name="model">The model.</param> /// <param name="treatNullsAsLists">if set to <c>true</c> treat null lists as empty lists.</param> /// <param name="createIfNotExists">if set to <c>true</c> create if not exists.</param> /// <returns> /// Saved layout entity /// </returns> public Layout SaveLayout(TemplateEditViewModel model, bool treatNullsAsLists = true, bool createIfNotExists = false) { if (model.Options != null) { optionService.ValidateOptionKeysUniqueness(model.Options); } unitOfWork.BeginTransaction(); var isNew = model.Id.HasDefaultValue(); Layout template = null; if (!isNew) { template = repository.AsQueryable <Layout>() .Where(f => f.Id == model.Id) .FetchMany(f => f.LayoutRegions) .ToList() .FirstOrDefault(); isNew = template == null; if (isNew && !createIfNotExists) { throw new EntityNotFoundException(typeof(Layout), model.Id); } } if (template == null) { template = new Layout { Id = model.Id }; } else if (model.Version > 0) { template.Version = model.Version; } template.Name = model.Name; template.LayoutPath = model.Url; template.PreviewUrl = model.PreviewImageUrl; // Set null list as empty if (treatNullsAsLists) { model.Options = model.Options ?? new List <OptionViewModel>(); model.Regions = model.Regions ?? new List <TemplateRegionItemViewModel>(); } // Edits or removes regions. if (model.Regions != null) { if (template.LayoutRegions != null && template.LayoutRegions.Any()) { foreach (var region in template.LayoutRegions) { var requestRegion = model.Regions != null ? model.Regions.FirstOrDefault(f => f.Identifier.ToLowerInvariant() == region.Region.RegionIdentifier.ToLowerInvariant()) : null; if (requestRegion != null && region.Region.RegionIdentifier.ToLowerInvariant() == requestRegion.Identifier.ToLowerInvariant()) { region.Description = requestRegion.Description; repository.Save(region); } else { repository.Delete(region); } } } if (template.LayoutRegions == null) { template.LayoutRegions = new List <LayoutRegion>(); } var regions = GetRegions(model.Regions); foreach (var requestRegionOption in model.Regions) { if (!template.LayoutRegions.Any(f => f.Region.RegionIdentifier.Equals(requestRegionOption.Identifier, StringComparison.InvariantCultureIgnoreCase))) { var region = regions.Find(f => f.RegionIdentifier.Equals(requestRegionOption.Identifier, StringComparison.InvariantCultureIgnoreCase)); if (region == null) { if (requestRegionOption.Description == null) { requestRegionOption.Description = string.Empty; } var regionOption = new Region { RegionIdentifier = requestRegionOption.Identifier }; template.LayoutRegions.Add(new LayoutRegion { Description = requestRegionOption.Description, Region = regionOption, Layout = template }); repository.Save(regionOption); } else { var layoutRegion = new LayoutRegion { Description = requestRegionOption.Description, Region = region, Layout = template }; template.LayoutRegions.Add(layoutRegion); repository.Save(layoutRegion); } } } } if (model.Options != null) { optionService.SetOptions <LayoutOption, Layout>(template, model.Options); } repository.Save(template); unitOfWork.Commit(); // Notify if (isNew) { Events.PageEvents.Instance.OnLayoutCreated(template); } else { Events.PageEvents.Instance.OnLayoutUpdated(template); } return(template); }
/// <summary> /// 构造方法 /// </summary> /// <param name="vm"></param> public TemplateEditService(TemplateEditViewModel vm) { Transaction = new Transaction(); PaintContext = new PaintContext(); _vm = vm; }
public ViewResult EditCategory(int id) { TemplateEditViewModel model = GetModel(id); return(View(model)); }