public ActionResult AppDefEdit(Guid id)
        {
            try
            {
                var listSelectListItems = new List<SelectListItem>();
                var schedules = _repository.Fetch<Scheduler>().Where(p => p.Active == MyEnums.Active.Enable);
                foreach (var n in schedules)
                {
                    var selectList = new SelectListItem()
                    {
                        Text = n.Name,
                        Value = n.Id.ToString()
                    };
                    listSelectListItems.Add(selectList);
                }

                var model = _repository.Find<ApplicationDefinition>(id);
                var appDefEdit = new AppDefViewModel
                {
                    Id = model.Id,
                    Name = model.Name,
                    Priority = model.Priority,
                    Description = model.Description,
                    EndDate = model.EndDate,
                    StartDate = model.StartDate,
                    Schedules = listSelectListItems
                };
                return View(appDefEdit);
            }
            catch (Exception ex)
            {
                _logs.LogError(User.Identity.GetUserName(), "AppDefEdit_HTTPGET", "Error: " + ex.Message,
                    Request.ServerVariables["REMOTE_ADDR"]);
                return HttpNotFound();
            }
        }
        public ActionResult AppDefEdit(AppDefViewModel appDefViewModel)
        {
            try
            {
                string fileNames = "";
                int fileCnt = 0;
                var uploaded = false;

                if (ModelState.IsValid)
                {
                    var applicationDefinition = _repository.Find<ApplicationDefinition>(appDefViewModel.Id);
                    var fileDirectory = Path.Combine(Server.MapPath("~/App_Data/Applications/"),
                        applicationDefinition.Name + "_" + DateTime.Now.ToString("yyyy MMMM dd"));
                    if (!Directory.Exists(fileDirectory))
                    {
                        Directory.CreateDirectory(fileDirectory);
                    }
                    else
                    {
                        foreach (var file in Directory.GetFiles(fileDirectory))
                        {
                            System.IO.File.Delete(file);
                        }
                    }
                    foreach (var file in appDefViewModel.Files)
                    {
                        if (file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path = Path.Combine(fileDirectory, fileName);
                            file.SaveAs(path);
                            uploaded = true;
                            fileNames += Path.GetFileName(fileName) + " || ";
                            fileCnt++;
                        }
                    }
                    if (uploaded)
                    {
                        var schedule = _repository.Find<Scheduler>(Guid.Parse(appDefViewModel.ScheduleVal));
                        applicationDefinition.Maker = User.Identity.GetUserName();
                        applicationDefinition.EditDateTime = DateTime.Now;
                        applicationDefinition.Status = MyEnums.StatusOptions.Added;
                        applicationDefinition.Active = MyEnums.Active.Disable;
                        applicationDefinition.Name = appDefViewModel.Name;
                        applicationDefinition.StartDate = appDefViewModel.StartDate;
                        applicationDefinition.EndDate = appDefViewModel.EndDate;
                        applicationDefinition.ApplicationPath = fileDirectory;
                        applicationDefinition.Description = appDefViewModel.Description;
                        applicationDefinition.Priority = appDefViewModel.Priority;
                        applicationDefinition.SchedulerId = schedule.Id;
                        applicationDefinition.FileCount = fileCnt;
                        applicationDefinition.FileNames = fileNames;
                        //_repository.SaveNew(applicationDefinition);
                        _repository.SaveUpdate(applicationDefinition);
                        _logs.LogAudit(User.Identity.GetUserName(), "AppDefEdit_HTTPPOST", Request.UserHostName,
                            "Edited Application :" + applicationDefinition.Name, "Edited");
                    }
                    else
                    {
                        ModelState.AddModelError("",  " Select Files to Upload!");
                        return View();
                    }

                }

                return View();
            }
            catch (Exception ex)
            {
                _logs.LogError(User.Identity.GetUserName(), "AppDefEdit_HTTPPOST", "Error: " + ex.Message,
                    Request.ServerVariables["REMOTE_ADDR"]);
                return HttpNotFound();
            }
        }
 public ActionResult AppDefCreate()
 {
     try
     {
         var listSelectListItems = new List<SelectListItem>();
         var schedules = _repository.Fetch<Scheduler>().Where(p => p.Active == MyEnums.Active.Enable);
         foreach (var n in schedules)
         {
             var selectList = new SelectListItem()
             {
                 Text = n.Name,
                 Value = n.Id.ToString()
             };
             listSelectListItems.Add(selectList);
         }
         var appDefViewModel = new AppDefViewModel();
         appDefViewModel.Schedules = listSelectListItems;
         return View(appDefViewModel);
     }
     catch (Exception ex)
     {
         _logs.LogError(User.Identity.GetUserName(), "AppDefCreate_HTTPGET", "Error: " + ex.Message, Request.ServerVariables["REMOTE_ADDR"]);
         return HttpNotFound();
     }
 }