/// <summary>
        /// Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>ActionResult.</returns>
        public ActionResult Edit(int id)
        {

            if (Session["CurrentSchedule"] == null)
            {
                return RedirectToAction("Index", "Schedule");

            }
            var schedule = (Schedule)Session["CurrentSchedule"];
              int days = DateTime.DaysInMonth(schedule.Year, schedule.Month);
            var model = new TimeSlotViewModel();
            model.CurrentSchedule= schedule;
            model.Offices = new OfficeAppService().GetOfficesByEmployeeId(schedule.EmployeeId);
            model.DaysInMonth = days;

            




            if (id != -1)
            {
                var svc = new TimeSlotAppService();
                var o = svc.GetTimeSlot(id);
                model.TimeSlotId = o.TimeSlotId;
                model.ScheduleId = o.ScheduleId;
                model.StartTime = o.StartTime;
                model.EndTime = o.EndTime;
                model.Day = o.Day;
                model.OfficeId = o.OfficeId;
                model.StartTimeText = o.StartTime.ToShortTimeString();
                model.EndTimeText = o.EndTime.ToShortTimeString();
              




            }
            else
            {
                model.Action = "-1";
                model.TimeSlotId = -1;
                model.ScheduleId = schedule.ScheduleId;
                model.StartTime = DateTime.Now;
                model.EndTime = DateTime.Now;
                model.Day = 1;
                model.OfficeId = -1;
                model.StartTimeText = DateTime.Now.ToShortTimeString();
                model.EndTimeText = DateTime.Now.ToShortTimeString();
            }



            return View(model);
        }
        public ActionResult Edit(TimeSlotViewModel model)
        {
            if (Session["CurrentSchedule"] == null)
            {
                return RedirectToAction("Index", "Schedule");

            }
            var schedule = (Schedule)Session["CurrentSchedule"];

            int days = DateTime.DaysInMonth(schedule.Year, schedule.Month);
            model.CurrentSchedule = schedule;
            model.Offices = new OfficeAppService().GetOfficesByEmployeeId(schedule.EmployeeId);
            model.DaysInMonth = days; ;

            DateTime parsedDate1 = DateTime.ParseExact(model.StartTimeText, "H:mm", System.Globalization.CultureInfo.InvariantCulture);
            DateTime parsedDat2 = DateTime.ParseExact(model.EndTimeText, "H:mm", System.Globalization.CultureInfo.InvariantCulture);
                



            try
            {
                var svc = new TimeSlotAppService();

                var o = new TimeSlot
                {
                    TimeSlotId= model.TimeSlotId,
                    ScheduleId = schedule.ScheduleId,
                    Day = model.Day,
                    StartTime = parsedDate1,
                    EndTime = parsedDat2,
                    OfficeId = model.OfficeId,
                    
          
                    

                };

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

                        svc.SaveTimeSlot(o);
                    }
                    else
                    {
                        svc.RemoveTimeSlot(model.TimeSlotId);
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }

            return View(model);
        }