/// <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 ScheduleViewModel();
            model.CurrentEmployee= employee;
            


            if (id != -1)
            {
                var svc = new ScheduleAppService();
                var o = svc.GetSchedule(id);
                model.ScheduleId= o.ScheduleId;
                model.EmployeeId = o.EmployeeId;
                model.Month = o.Month;
                model.Year = o.Year;
                
      
            

            }
            else
            {
                model.Action = "-1";
                model.ScheduleId = -1;
                model.Month = DateTime.Now.Month;
                model.EmployeeId =employee.EmployeeId;
                model.Year = DateTime.Now.Year;
                
            }



            return View(model);
        }
        public DataTablesResult<ScheduleViewModel> GetAllRecords(DataTablesParam dataTableParam)
        {
              if (Session["CurrentEmployee"] == null)
            {
                RedirectToAction("Index", "Employee");

            }
         
             var employee = (Employee)Session["CurrentEmployee"];

            var svc = new ScheduleAppService();
          List<Schedule> ats = svc.GetAllScheduleByEmployeeId(employee.EmployeeId);
            var atVm = new List<ScheduleViewModel>();

            var ci = new CultureInfo("es-CO");
            foreach (var itm in ats)
            {

                var itmVm = new ScheduleViewModel
                {

               
                    ScheduleId= itm.ScheduleId,
                    EmployeeId = itm.EmployeeId,
                    Month=itm.Month,
                    Year = itm.Year,
                    MonthName = new DateTime(2010, itm.Month, 1).ToString("MMMM", ci)
                };

              




                var sb = new StringBuilder();

                string editUrl = Url.Action("Edit", "Schedule");
                string timeslotUrl = Url.Action("Index", "TimeSlot");
                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>&nbsp;Nuevo Registro</a></li>");
                sb.AppendLine("<li><a href=\"" + editUrl + "?id=" + itmVm.ScheduleId+ "\"><i class=\"fa fa-edit\"></i>&nbsp;Editar Agenda</a></li>");
                sb.AppendLine("<li><a href=\"" + timeslotUrl + "?id=" + itmVm.ScheduleId + "\"><i class=\"fa fa-edit\"></i>&nbsp;Asignar Disponibilidad</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(ScheduleViewModel model)
        {
            if (Session["CurrentEmployee"] == null)
            {
                return RedirectToAction("Index", "Employee");

            }
            var employee = (Employee)Session["CurrentEmployee"];

    
            model.CurrentEmployee = employee;
            


            try
            {
                var svc = new ScheduleAppService();

                var o = new Schedule
                {
                    ScheduleId= model.ScheduleId,
                    EmployeeId = employee.EmployeeId,
                    Year = model.Year,
                    Month=model.Month
          
                    

                };

                if (model.Action == "-1")
                {
                    var exist = svc.GetSchedule(model.ScheduleId)!=null;
                    if (!exist)
                    {
                        svc.AddSchedule(o);
                        ViewBag.Feed = 0;
                    }
                    else
                    {
                        model.Action = "-1";
                        ViewBag.Feed = 3;
                        return View(model);
                    }
                }
                else
                {
                    o.ScheduleId= model.ScheduleId;
                    if (model.IsDeleteAction == 0)
                    {

                        svc.SaveSchedule(o);
                    }
                    else
                    {
                        svc.RemoveSchedule(model.ScheduleId);
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }

            return View(model);
        }