/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>ActionResult.</returns> public ActionResult Edit(int id) { if (Session["CurrentEmployee"] == null) { return RedirectToAction("Index", "Employee"); } var employee = (Employee)Session["CurrentEmployee"]; var model = new OfficeViewModel(); model.CurrentEmployee= employee; model.Countries = HealthHelper.GetAllCountries(); if (id != -1) { var svc = new OfficeAppService(); var o = svc.GetOffice(id); model.OfficeId = o.OfficeId; model.EmployeeId = o.EmployeeId; model.GeoCityId = o.GeoCityId; model.GeoStateId = o.GeoCity.GeoStateId; model.GeoCountryId = o.GeoCity.GeoState.GeoCountryId; model.Address = o.Address; model.Number = o.Number; } else { model.Action = "-1"; model.OfficeId = -1; model.EmployeeId = employee.EmployeeId; model.GeoCityId = "-1"; model.GeoStateId = "-1"; model.GeoCountryId = "-1"; model.Address =String.Empty; model.Number = String.Empty; } return View(model); }
public DataTablesResult<OfficeViewModel> GetAllRecords(DataTablesParam dataTableParam) { if (Session["CurrentEmployee"] == null) { RedirectToAction("Index", "Employee"); } var employee = (Employee)Session["CurrentEmployee"]; var svc = new OfficeAppService(); List<Office> ats = svc.GetOfficesByEmployeeId(employee.EmployeeId); var atVm = new List<OfficeViewModel>(); foreach (var itm in ats) { var itmVm = new OfficeViewModel { OfficeId= itm.OfficeId, Address = itm.Address, EmployeeId = employee.EmployeeId, Number = itm.Number, GeoStateName=itm.GeoCity.GeoState.Name, GeoCityName = itm.GeoCity.Name, }; var sb = new StringBuilder(); string editUrl = Url.Action("Edit", "Office"); 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 Registro</a></li>"); sb.AppendLine("<li><a href=\"" + editUrl + "?id=" + itmVm.OfficeId+ "\"><i class=\"fa fa-edit\"></i> Editar Oficina</a></li>"); sb.AppendLine("</ul>"); sb.AppendLine("</div>"); var actionButton = sb.ToString(); itmVm.ActionButton = actionButton; atVm.Add(itmVm); } var atmVmQueryable = atVm.AsQueryable(); return DataTablesResult.Create(atmVmQueryable, dataTableParam); }
public ActionResult Edit(OfficeViewModel model) { if (Session["CurrentEmployee"] == null) { return RedirectToAction("Index", "Employee"); } var employee = (Employee)Session["CurrentEmployee"]; model.CurrentEmployee = employee; model.Countries = HealthHelper.GetAllCountries(); try { var svc = new OfficeAppService(); var o = new Office { OfficeId= model.OfficeId, EmployeeId = employee.EmployeeId, Address = model.Address, GeoCityId = model.GeoCityId, Number = model.Number, }; if (model.Action == "-1") { var exist = svc.GetOffice(model.OfficeId)!=null; if (!exist) { svc.AddOffice(o); ViewBag.Feed = 0; } else { model.Action = "-1"; ViewBag.Feed = 3; return View(model); } } else { o.OfficeId= model.OfficeId; if (model.IsDeleteAction == 0) { svc.SaveOffice(o); } else { svc.RemoveOffice(model.OfficeId); } ViewBag.Feed = 0; } } catch (Exception) { ViewBag.Feed = 1; } return View(model); }