//
 // GET: /Application/Add
 public ActionResult Add()
 {
     var viewModel = new ApplicationViewModel() { ApplicationId = 0 };
     //return View();
     return PartialView("_AddOrEdit", viewModel);
 }
        //
        // GET: /Application/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var application = _applicationRepository.GetById(id);
                var application = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == id);
                if (application != null)
                {
                    var viewModel = new ApplicationViewModel() { ApplicationId = application.ApplicationId, ApplicationName = application.ApplicationName, Description = application.Description, ApplicationTitle = application.ApplicationTitle };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        public ActionResult Save(ApplicationViewModel applicationViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //add
                    if (applicationViewModel.ApplicationId == 0 && applicationViewModel.ActionName == "Add")
                    {
                        var model = new TblApplication() { ApplicationId = applicationViewModel.ApplicationId, ApplicationName = applicationViewModel.ApplicationName, Description = applicationViewModel.Description, ApplicationTitle = applicationViewModel.ApplicationTitle };

                        _applicationRepository.Insert(model);
                    }
                    else if (applicationViewModel.ActionName == "Edit") //edit
                    {
                        TblApplication application = _applicationRepository.GetById(applicationViewModel.ApplicationId);

                        if (application != null)
                        {

                            application.ApplicationId = applicationViewModel.ApplicationId;
                            application.ApplicationName = applicationViewModel.ApplicationName;
                            application.Description = applicationViewModel.Description;
                            application.ApplicationTitle = applicationViewModel.ApplicationTitle;

                            _applicationRepository.Update(application);

                        }
                        else
                        {
                            return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject()));
                        }

                    }

                    _applicationRepository.Save();

                    return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, applicationViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully."));

                }

                return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, MessageType.success.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState)));
            }
            catch (Exception ex)
            {
                return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, MessageType.success.ToString(), ExceptionHelper.ExceptionMessageFormat(ex)));
            }
        }