public ActionResult Create(CalendarViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.StartDate < SessionHelper.Calendar.EndDate)
                {
                    ModelState.AddModelError("Error", "Start date is overlaping with previous period!");
                }
                else if (model.StartDate > model.EndDate)
                {
                    ModelState.AddModelError("Error", "Invalid Dates!");
                }
                else
                {
                    ////Not sure about the validity of this code,
                    ////To be checked later.
                    //////////////////////////////////////////////////
                    ////Calendar duplicateRecord = service.getCalendarByPeriod(AuthenticationHelper.User.CompanyId, model.SOBId, model.StartDate, model.EndDate);
                    //////////////////////////////////////////////////
                    ////if (duplicateRecord == null)
                    ////{
                        model.ClosingStatus = "Open";
                        string result = service.Insert(mapModel(model));    ////TODO: mapper should be in service
                        return RedirectToAction("Index");
                    ////}
                    ////else
                    ////{
                    ////    ModelState.AddModelError("Error", "Period Already Exists!");
                    ////}
                }
            }

            return View(model);
        }
        public ActionResult Edit(CalendarViewModel model)
        {
            if (ModelState.IsValid)
            {
                string result = service.Update(mapModel(model));
                return RedirectToAction("Index");
            }

            return View(model);
        }
        public ActionResult ChangeStatus(CalendarViewModel model)
        {
            if (ModelState.IsValid)
            {
                Calendar entity = service.GetSingle(model.Id.ToString(), AuthenticationHelper.User.CompanyId);
                entity.ClosingStatus = model.ClosingStatus;
                string result = service.Update(entity);
                return RedirectToAction("Index");
            }

            return View(model);
        }
 public ActionResult Edit(string id)
 {
     CalendarViewModel model = new CalendarViewModel(service.GetSingle(id, AuthenticationHelper.User.CompanyId));
     return View(model);
 }
 private Calendar mapModel(CalendarViewModel model)
 {
     return new Calendar
     {
         Adjusting = model.Adjusting,
         ClosingStatus = model.ClosingStatus,
         CompanyId = AuthenticationHelper.User.CompanyId,
         CreateDate = DateTime.Now,
         EndDate = model.EndDate,
         Id = model.Id,
         PeriodName = model.PeriodName,
         PeriodQuarter = model.PeriodQuarter,
         PeriodYear = model.PeriodYear,
         SeqNumber = model.SeqNumber,
         SOBId = model.SOBId,
         StartDate = model.StartDate,
         UpdateDate = DateTime.Now
     };
 }
 public ActionResult Create(long sobId)
 {
     CalendarViewModel model = new CalendarViewModel();
     model.SOBId = sobId;
     SessionHelper.Calendar = model;
     return View(model);
 }