Ejemplo n.º 1
0
        public ActionResult Edit(SavePopDashboardViewModel viewModel, HttpPostedFileBase file)
        {
            var request = viewModel.MapTo <SavePopDashboardRequest>();

            ProcessAttachment(viewModel, request);
            var response = _popDashboardService.SavePopDashboard(request);

            TempData["IsSuccess"] = response.IsSuccess;
            TempData["Message"]   = response.Message;
            if (response.IsSuccess)
            {
                return(RedirectToAction("Index"));
            }
            return(View("Create", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            var viewModel  = new SavePopDashboardViewModel();
            var StatusList = new List <SelectListItem>()
            {
                new SelectListItem {
                    Value = "Not Start Yet", Text = "Not Start Yet"
                },
                new SelectListItem {
                    Value = "In Progress", Text = "In Progress"
                },
                new SelectListItem {
                    Value = "Finish", Text = "Finish"
                }
            };

            viewModel.StatusOptions = StatusList;
            return(View(viewModel));
        }
Ejemplo n.º 3
0
 private void ProcessAttachment(SavePopDashboardViewModel viewModel, SavePopDashboardRequest request)
 {
     if (viewModel.Attachments.Count > 0)
     {
         var validImageTypes = new string[]
         {
             "image/gif",
             "image/jpeg",
             "image/pjpeg",
             "image/png"
         };
         var pdfType    = "application/pdf";
         var excelTypes = new string[] {
             "application/vnd.ms-excel",
             "application/msexcel",
             "application/x-msexcel",
             "application/x-ms-excel",
             "application/x-excel",
             "application/x-dos_ms_excel",
             "application/xls",
             "application/x-xls",
             "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
         };
         var docTypes = new string[] {
             "application/msword",
             "application/msword",
             "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
             "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
             "application/vnd.ms-word.document.macroEnabled.12",
             "application/vnd.ms-word.template.macroEnabled.12"
         };
         var pptTypes = new string[] {
             "application/vnd.ms-powerpoint",
             "application/vnd.ms-powerpoint",
             "application/vnd.ms-powerpoint",
             "application/vnd.ms-powerpoint",
             "application/vnd.openxmlformats-officedocument.presentationml.presentation",
             "application/vnd.openxmlformats-officedocument.presentationml.template",
             "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
             "application/vnd.ms-powerpoint.addin.macroEnabled.12",
             "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
             "application/vnd.ms-powerpoint.template.macroEnabled.12",
             "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"
         };
         foreach (var attachment in viewModel.Attachments)
         {
             if (attachment.File != null)
             {
                 //var filename = Path.GetFileName(attachment.File.FileName);
                 string type = null;
                 if (attachment.File.ContentType == pdfType)
                 {
                     type = "pdf";
                 }
                 else if (validImageTypes.Contains(attachment.File.ContentType))
                 {
                     type = "image";
                 }
                 else if (excelTypes.Contains(attachment.File.ContentType))
                 {
                     type = "excel";
                 }
                 else if (docTypes.Contains(attachment.File.ContentType))
                 {
                     type = "doc";
                 }
                 else if (pptTypes.Contains(attachment.File.ContentType))
                 {
                     type = "ppt";
                 }
                 else
                 {
                     type = "blank";
                 }
                 if (!Directory.Exists(Server.MapPath(PathConstant.PopAttachmentPath)))
                 {
                     Directory.CreateDirectory(Server.MapPath(PathConstant.PopAttachmentPath));
                 }
                 var filename       = attachment.File.FileName;
                 var uniqueFilename = RandomString(8) + MakeValidFileName(attachment.File.FileName).Replace(" ", "_");
                 var filePath       = Path.Combine(Server.MapPath(PathConstant.PopAttachmentPath), uniqueFilename);
                 var url            = PathConstant.PopAttachmentPath + "/" + uniqueFilename;
                 attachment.File.SaveAs(filePath);
                 var attachmentReq = new SavePopDashboardRequest.Attachment
                 {
                     Id       = attachment.Id,
                     FileName = url,
                     Alias    = string.IsNullOrEmpty(attachment.Alias) ? filename : attachment.Alias,
                     Type     = type
                 };
                 request.AttachmentFiles.Add(attachmentReq);
             }
             else
             {
                 if (attachment.Id != 0)
                 {
                     var attachmentReq = new SavePopDashboardRequest.Attachment
                     {
                         Id    = attachment.Id,
                         Alias = attachment.Alias,
                     };
                     request.AttachmentFiles.Add(attachmentReq);
                 }
             }
         }
     }
 }