public ActionResult Edit(ActiveComponentViewModel model) { try{ var svc = new ActiveComponentAppService(); var o = new ActiveComponent{ ActiveComponentId = model.ActiveComponentId, Name = model.Name }; if (model.Action == "-1"){ var exist = svc.GetActiveComponent(model.ActiveComponentId) != null; if (!exist){ svc.AddActiveComponent(o); this.ViewBag.Feed = 0; } else{ model.Action = "-1"; this.ViewBag.Feed = 3; return this.View(model); } } else{ o.ActiveComponentId = model.ActiveComponentId; if (model.IsDeleteAction == 0) svc.SaveActiveComponent(o); else svc.RemoveActiveComponent(model.ActiveComponentId); this.ViewBag.Feed = 0; } } catch (Exception){ this.ViewBag.Feed = 1; } return this.View(model); }
/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>ActionResult.</returns> public ActionResult Edit(int id) { var model = new ActiveComponentViewModel(); if (id != -1){ var svc = new ActiveComponentAppService(); var o = svc.GetActiveComponent(id); model.ActiveComponentId = o.ActiveComponentId; model.Name = o.Name; } else{ model.Action = "-1"; model.ActiveComponentId = -1; model.Name = string.Empty; } return this.View(model); }
public DataTablesResult<ActiveComponentViewModel> GetAllRecords(DataTablesParam dataTableParam) { var svc = new ActiveComponentAppService(); var lst = svc.GetAllActiveComponent(); var lstVm = new List<ActiveComponentViewModel>(); foreach (var itm in lst){ var itmVm = new ActiveComponentViewModel{ Name = itm.Name, ActiveComponentId = itm.ActiveComponentId }; var sb = new StringBuilder(); var editUrl = this.Url.Action("Edit", "ActiveComponent"); sb.AppendLine("<div class=\"btn-group\">"); sb.AppendLine("<button type=\"button\" class=\"btn btn-default dropdown-toggle\" data-toggle=\"dropdown\" aria-expanded=\"false\">"); sb.AppendLine("Acciones <span class=\"caret\"></span>"); sb.AppendLine("</button>"); sb.AppendLine("<ul class=\"dropdown-menu\" role=\"menu\">"); sb.AppendLine("<li><a href=\"" + editUrl + "?id=-1\"><i class=\"fa fa-plus\"></i> Nuevo Componente Activo</a></li>"); sb.AppendLine( "<li><a href=\"" + editUrl + "?id=" + itmVm.ActiveComponentId + "\"><i class=\"fa fa-edit\"></i> Editar Componente Activo</a></li>"); sb.AppendLine("</ul>"); sb.AppendLine("</div>"); var actionButton = sb.ToString(); itmVm.ActionButton = actionButton; lstVm.Add(itmVm); } var lstVmQueryable = lstVm.AsQueryable(); return DataTablesResult.Create(lstVmQueryable, dataTableParam); }