public ActionResult Delete(DailyPracticePaperEditViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var result = _dailyPracticePaperService.Delete(viewModel.DailyPracticePaperId);
         if (result.Success)
         {
             Success(result.Results.FirstOrDefault().Message);
             ModelState.Clear();
         }
         else
         {
             _logger.Warn(result.Results.FirstOrDefault().Message);
             Warning(result.Results.FirstOrDefault().Message, true);
         }
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult Edit(DailyPracticePaperEditViewModel viewModel)
        {
            ViewBag.fileName = viewModel.FileName;
            var cmsResult = new CMSResult();

            if (ModelState.IsValid)
            {
                var practicePaper = _repository.Project <DailyPracticePaper, bool>(papers => (from paper in papers where paper.DailyPracticePaperId == viewModel.DailyPracticePaperId select paper).Any());
                if (!practicePaper)
                {
                    _logger.Warn(string.Format("Daily practice paper not exists '{0}'.", ""));
                    Danger(string.Format("Daily practice paper not exists '{0}'.", ""));
                }
                string filePath = "";
                if (viewModel.FilePath != null)
                {
                    Guid guid = Guid.NewGuid();
                    if (viewModel.AttachmentDescription == null)
                    {
                        _logger.Warn("Please enter attachment description.");
                        Warning("Please enter attachment description.", true);
                        return(View(viewModel));
                    }
                    else if (viewModel.FileName == null || viewModel.FileName == "")
                    {
                        if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType))
                        {
                            viewModel.FileName = string.Format("{0}.jpg", guid);
                        }
                        else
                        {
                            viewModel.FileName = string.Format("{0}.pdf", guid);
                        }
                    }
                    else
                    {
                        if (Common.Constants.ImageTypes.Contains(viewModel.FilePath.ContentType))
                        {
                            viewModel.FileName = string.Format("{0}.jpg", viewModel.FileName.Split('.')[0]);
                        }
                        else
                        {
                            viewModel.FileName = string.Format("{0}.pdf", viewModel.FileName.Split('.')[0]);
                        }
                    }
                    filePath = viewModel.FileName;
                    if (viewModel.FilePath.ContentLength == 0)
                    {
                        cmsResult.Results.Add(new Result {
                            Message = "Please choose file", IsSuccessful = false
                        });
                    }
                }
                else
                {
                    filePath = null;
                }
                var fileNameSelect = (viewModel.FilePath != null) ? filePath : viewModel.FileName;
                var description    = viewModel.Description.Replace("\r\n", "<br />");
                var result         = _dailyPracticePaperService.Update(new DailyPracticePaper
                {
                    DailyPracticePaperId   = viewModel.DailyPracticePaperId,
                    Description            = description,
                    AttachmentDescription  = viewModel.AttachmentDescription != null ? viewModel.AttachmentDescription : "",
                    DailyPracticePaperDate = viewModel.DailyPracticePaperDate,
                    FileName = fileNameSelect
                });
                if (result.Success)
                {
                    if (viewModel.FilePath != null)
                    {
                        string PaperPath  = Server.MapPath(string.Concat("~/PDF/", Common.Constants.DailyPracticePaperFile));
                        var    pathToSave = Path.Combine(PaperPath, viewModel.FileName);
                        viewModel.FilePath.SaveAs(pathToSave);
                    }
                    Success(result.Results.FirstOrDefault().Message);
                    ModelState.Clear();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    _logger.Warn(result.Results.FirstOrDefault().Message);
                    Warning(result.Results.FirstOrDefault().Message, true);
                }
            }
            return(View(viewModel));
        }