Esempio n. 1
0
        public async Task <bool> UpLoadFile(List <IFormFile> files, BaiPost model)
        {
            if (files == null)
            {
                return(true);
            }
            string[] permittedExtensions = { ".png", ".jpeg", ".jpg" };
            string   uniqueFileName      = null;

            foreach (var file in files)
            {
                ImgBaiPost img = new ImgBaiPost();
                var        ext = Path.GetExtension(file.FileName).ToLowerInvariant();

                if (string.IsNullOrEmpty(ext) || !permittedExtensions.Contains(ext))
                {
                    return(false);
                }
                string UploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "img/ThaoLuan");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + file.FileName;
                string filePath = Path.Combine(UploadsFolder, uniqueFileName);
                await file.CopyToAsync(new FileStream(filePath, FileMode.Create));

                ImgBaiPost imgBaiPost = new ImgBaiPost {
                    IdbaiPost  = model.Id,
                    TenAnh     = file.FileName,
                    KichThuoc  = FileSizeFormatter.FormatSize(file.Length),
                    AnhDinhKem = uniqueFileName
                };
                model.ImgBaiPost.Add(imgBaiPost);
            }
            return(true);
        }
Esempio n. 2
0
        private void setinfo()
        {
            BitmapSource iconApp;
            //GET INFO
            FileInfo        currentFileInfo   = new FileInfo(item.pathf);
            FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(item.pathf);
            string          pathico           = Path.Combine(SharedVar.settingspath, "icons", item.Title + ".png");

            if (File.Exists(pathico))
            {
                iconApp = new BitmapImage(new Uri(pathico));
            }
            else
            {
                //GET HQ ICON
                //  QuickZip.Tools.FileToIconConverter asd = new QuickZip.Tools.FileToIconConverter();
                iconApp = ExtractIco.extract(item.pathf);
            }

            //SET INFO
            var IcoApp     = b.FindName("IcoApp") as Image;
            var NameApp    = b.FindName("NameApp") as System.Windows.Controls.Label;
            var VersionApp = b.FindName("VersionApp") as System.Windows.Controls.Label;
            var Kind       = b.FindName("Kind") as System.Windows.Controls.Label;
            var Size       = b.FindName("Size") as System.Windows.Controls.Label;
            var Created    = b.FindName("Created") as System.Windows.Controls.Label;
            var Modified   = b.FindName("Modified") as System.Windows.Controls.Label;
            var LastOpened = b.FindName("LastOpened") as System.Windows.Controls.Label;


            IcoApp.Source = iconApp; // Imaging.CreateBitmapSourceFromHIcon(ico.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            if (myFileVersionInfo.FileDescription != null)
            {
                NameApp.Content = myFileVersionInfo.FileDescription;
            }
            else
            {
                NameApp.Content = item.Title;
            }

            VersionApp.Content = myFileVersionInfo.FileVersion;
            Kind.Content       = item.textLabel;
            Size.Content       = FileSizeFormatter.FormatSize(item.Size);
            Created.Content    = currentFileInfo.CreationTime.ToString();
            Modified.Content   = currentFileInfo.LastWriteTime.ToString();
            LastOpened.Content = currentFileInfo.LastAccessTime.ToString();
        }
Esempio n. 3
0
        public async override Task <string> AllChildrenToString(string space)
        {
            space += " ";
            return(await Task.Run(async() =>
            {
                string toReturn = string.Empty;
                string tmpStr = string.Empty;

                foreach (Component s in _children)
                {
                    LengthOfFileOrDirectory += s.LengthOfFileOrDirectory;
                    tmpStr += space + await s.AllChildrenToString(space) + "\n" + Environment.NewLine;
                }

                FileSizeFormatter.sizesOfBrances.Add(LengthOfFileOrDirectory);

                toReturn += space + FileOrDirectory + ", ";
                toReturn += $"Size of this directory: {FileSizeFormatter.FormatSize(LengthOfFileOrDirectory)}, children: {_children.Count}\n" + Environment.NewLine;
                toReturn += tmpStr;

                return toReturn;
            }));
        }
 public async override Task <string> AllChildrenToString(string space)
 {
     return(await Task.Run(() => { return $"{space}{FileOrDirectory}, size: {FileSizeFormatter.FormatSize(LengthOfFileOrDirectory, _exceptionMessage)}\n" + Environment.NewLine; }));
 }
Esempio n. 5
0
        public Exception Open(string path)
        {
            file.Path = path;
            TitleChangedEvent?.Invoke(file.Name);

            TargaFile targaFile = TargaFile.Read(path);

            int width  = targaFile.Header.Width;
            int height = targaFile.Header.Height;

            WriteableBitmap bitmap = new WriteableBitmap(width, height, 90, 90, PixelFormats.Bgra32, null);

            byte[] buffer = new byte[width * height * 4];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int   pos     = (x + y * width) * 4;
                    var   lookupX = width - x - 1;
                    Color color   = targaFile.Pixels[lookupX, y];
                    buffer[pos]     = color.B;
                    buffer[pos + 1] = color.G;
                    buffer[pos + 2] = color.R;
                    buffer[pos + 3] = color.A;
                }
            }

            Int32Rect rect = new Int32Rect(0, 0, width, height);

            bitmap.WritePixels(rect, buffer, width * 4, 0);

            OutputImage.Source = bitmap;
            FileInfo fileInfo = new FileInfo(file.Path);

            InspectorContent = new InspectorContent(
                file.Name,
                new InspectorTableEntry[]
            {
                new InspectorTableEntry("Path", file.Path, file.Path),
                new InspectorTableEntry("File Size", FileSizeFormatter.FormatSize(fileInfo.Length)),
                new InspectorTableEntry("Creation time", fileInfo.CreationTime.ToString(CultureInfo.InvariantCulture)),
                new InspectorTableEntry("Last change", fileInfo.LastWriteTime.ToString(CultureInfo.InvariantCulture)),
                new InspectorTableEntry("Dimensions", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions1", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions2", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions3", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions4", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions5", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions6", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions7", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions8", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions9", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions11", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions12", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions13", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions14", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions15", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions16", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions17", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions18", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions19", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions21", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions22", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions23", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
                new InspectorTableEntry("Dimensions24", width + " x " + height, $"Height:\t{height}\nWidth:\t{width}"),
            },
                new Image()
            {
                Source = new DrawingImage()
                {
                    Drawing = (Drawing)FindResource("Image")
                }
            });

            return(null);
        }
Esempio n. 6
0
        //====================================================
        //Отобразить список каталогов/файлов в ListView
        //====================================================

        private void ShowFileSystemItems()
        {
            lv_files.BeginUpdate();

            //Очистим ListView

            lv_files.Items.Clear();

            if (fileSystemItems == null || fileSystemItems.Count == 0)
            {
                return;
            }

            //Установка столбцов для папок

            SetColumsForFolders();

            //Очистим кэш иконок и списки изображений

            iconCache.ClearIconCashAndLists(il_DiscFoldersFilesIcons_Small, il_DiscFoldersFilesIcons_Large);

            //Заполнение списка

            ListViewItem lviFile = null;

            foreach (FileSystemInfo file in fileSystemItems)
            {
                lviFile      = new ListViewItem();
                lviFile.Tag  = file;
                lviFile.Text = file.Name;

                //Каталог

                if (file is DirectoryInfo)
                {
                    lviFile.ImageIndex = 1;
                    lviFile.SubItems.Add("Folder");
                }

                //Файл

                else if (file is FileInfo)
                {
                    FileInfo currentFile = file as FileInfo;
                    if (currentFile == null)
                    {
                        return;
                    }

                    string fileExtention = currentFile.Extension.ToLower();

                    //====================================================
                    //Назначение иконку файлу
                    //====================================================

                    //Поиск в кеше

                    int iconIndex = iconCache.GetIconIndexByExtention(fileExtention);

                    //Есть в кэше

                    if (iconIndex != -1)
                    {
                        lviFile.ImageIndex = iconIndex;
                    }

                    //Нет в кэше

                    else
                    {
                        lviFile.ImageIndex = iconCache.AddIconForFile((FileInfo)file, il_DiscFoldersFilesIcons_Small, il_DiscFoldersFilesIcons_Large);
                    }
                    lviFile.SubItems.Add(FileSizeFormatter.FormatSize((((FileInfo)file).Length)));
                }
                lviFile.SubItems.Add(file.CreationTime.ToString());
                lviFile.SubItems.Add(file.LastWriteTime.ToString());

                lv_files.Items.Add(lviFile);

                lv_files.EndUpdate();
            }
        }
Esempio n. 7
0
        public ActionResult AddNotes(SellNotesAllDropdownList user,
                                     HttpPostedFileBase DisplayPictureFile,
                                     HttpPostedFileBase[] UploadedPdfFile,
                                     HttpPostedFileBase PreviewFile)
        {
            SellNote note = db.SellNotes.Where(x => x.ID == user.SellNote.ID).FirstOrDefault();

            if (note != null)
            {
                var SubmitValue = Request.Form["SavePublish"];
                if (SubmitValue == "save")
                {
                    string fileExtension;
                    string DisplayPictureFileName;
                    string PreviewFileName;

                    // check paid status
                    SellNotesEntity PaidOrNot  = new SellNotesEntity();
                    bool            PaidStatus = PaidOrNot.CheckNoteStatusPaidOrNot(user.IsPaidOrNot);
                    if (user.SellNote.SellingPrice != null)
                    {
                        note.SellingPrice = user.SellNote.SellingPrice;
                    }
                    else
                    {
                        note.SellingPrice = 0;
                    }

                    note.Course        = user.SellNote.Course;
                    note.CourseCode    = user.SellNote.CourseCode;
                    note.Discription   = user.SellNote.Discription;
                    note.NumberOfPages = user.SellNote.NumberOfPages;
                    note.Professor     = user.SellNote.Professor;

                    note.Title          = user.SellNote.Title;
                    note.UniversityName = user.SellNote.UniversityName;
                    note.IsPaid         = PaidStatus;
                    note.Category       = user.SellNote.Category;
                    note.Country        = user.SellNote.Country;
                    note.NoteType       = user.SellNote.NoteType;
                    note.Status         = Convert.ToInt32(Enums.ReferenceNoteStatus.Draft);
                    note.ActionedBy     = 3;
                    note.SellerID       = Convert.ToInt32(Session["ID"]);
                    note.IsActive       = true;
                    note.CreatedDate    = DateTime.Now;

                    db.SaveChanges();

                    if (DisplayPictureFile != null /*&& note.DisplayPicture != null*/)
                    {
                        fileExtension = Path.GetExtension(DisplayPictureFile.FileName);
                        fileExtension = fileExtension.ToLower();
                        if (fileExtension == ".jpg" || fileExtension == ".jpeg" || fileExtension == ".png" ||
                            fileExtension == ".JPG" || fileExtension == ".JPEG" || fileExtension == ".PNG")
                        {
                            DisplayPictureFileName = "DP_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                            var checkFile = CheckifPathExistForCurrentUser(note.ID) + note.DisplayPicture;
                            if (System.IO.File.Exists(checkFile))
                            {
                                System.IO.File.Delete(checkFile);
                            }
                            note.DisplayPicture = DisplayPictureFileName;

                            DisplayPictureFileName = CheckifPathExistForCurrentUser(note.ID) + DisplayPictureFileName;

                            DisplayPictureFile.SaveAs(DisplayPictureFileName);
                            db.SaveChanges();
                        }
                        else
                        {
                            ModelState.AddModelError("DisplayPictureFile", "Please upload image file of jpg, jpeg, png only");
                            user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                            user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                            user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                            return(View(user));
                        }
                    }



                    if (PreviewFile != null /*&& note.NotesPreview != null*/)
                    {
                        fileExtension = Path.GetExtension(PreviewFile.FileName);
                        fileExtension = fileExtension.ToLower();
                        if (fileExtension == ".pdf")
                        {
                            PreviewFileName = "PreviewFile_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                            var checkFile1 = CheckifPathExistForCurrentUser(note.ID) + note.NotesPreview;
                            if (System.IO.File.Exists(checkFile1))
                            {
                                System.IO.File.Delete(checkFile1);
                            }
                            note.NotesPreview = PreviewFileName;
                            PreviewFileName   = CheckifPathExistForCurrentUser(note.ID) + PreviewFileName;

                            PreviewFile.SaveAs(PreviewFileName);
                            db.SaveChanges();
                        }
                        else
                        {
                            ModelState.AddModelError("inputAddNotePreview", "Please upload file of pdf only");
                            user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                            user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                            user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                            return(View(user));
                        }
                    }



                    // logic is remain
                    if (UploadedPdfFile != null)
                    {
                        var FilePathForUploadedPdf = checkifPathExistForNoteAttachment(note.ID);
                        var attchedNote            = db.SellNoteAttachments.Where(x => x.NoteID == note.ID).ToList();

                        DirectoryInfo di = new DirectoryInfo(FilePathForUploadedPdf);
                        foreach (FileInfo files in di.GetFiles())
                        {
                            files.Delete();
                        }
                        foreach (var file in attchedNote)
                        {
                            db.SellNoteAttachments.Remove(file);
                            db.SaveChanges();
                        }

                        long Length = 0;
                        foreach (HttpPostedFileBase file in UploadedPdfFile)
                        {
                            fileExtension = Path.GetExtension(file.FileName);
                            fileExtension = fileExtension.ToLower();
                            //Checking file is available to save.
                            if (file != null && fileExtension == ".pdf")
                            {
                                var InputFileName = Path.GetFileNameWithoutExtension(file.FileName);
                                var attachment    = new SellNoteAttachment()
                                {
                                    NoteID   = note.ID,
                                    FileName = InputFileName,
                                    FilePath = FilePathForUploadedPdf,
                                    IsActive = true
                                };
                                db.SellNoteAttachments.Add(attachment);
                                db.SaveChanges();
                                int AttachmentID = attachment.ID;

                                var UploadedPdfFileName = AttachmentID.ToString() + "_" + InputFileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                attachment.FileName = UploadedPdfFileName;
                                var destinationFileLocation = Path.Combine(FilePathForUploadedPdf, UploadedPdfFileName);
                                file.SaveAs(destinationFileLocation);
                                Length = Length + file.ContentLength;
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("inputAdNoteUploadNotes", "Please upload file of pdf only");
                                user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                return(View(user));
                            }
                        }

                        note.AttachmentSize = FileSizeFormatter.FormatSize(Length);
                        db.SaveChanges();
                    }

                    return(RedirectToAction("AddNotes", "Dashboard"));
                }

                else if (SubmitValue == "publish")
                {
                    note.Status        = Convert.ToInt32(Enums.ReferenceNoteStatus.SubmittedForReview);
                    note.PublishedDate = DateTime.Now;
                    db.SaveChanges();

                    // Mail Sending Code
                    int  id       = Convert.ToInt32(Session["ID"]);
                    User SendMail = db.Users.Where(x => x.ID == id).FirstOrDefault();

                    var sender   = new MailAddress(ConstantStrings.supportEmail, ConstantStrings.supportName);
                    var receiver = new MailAddress("*****@*****.**", "Admin");
                    var password = ConstantStrings.supportPassword;
                    var body     = string.Empty;
                    var subject  = SendMail.FirstName + " sent his note for review";

                    using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplates/PublishNoteNotification.html")))
                    {
                        body = reader.ReadToEnd();
                    }
                    body = body.Replace("{SellerName}", SendMail.FirstName);
                    body = body.Replace("{NoteTitle}", note.Title);

                    var smtp = new SmtpClient
                    {
                        Host                  = ConfigurationManager.AppSettings["Host"],
                        Port                  = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
                        EnableSsl             = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]),
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = Convert.ToBoolean(ConfigurationManager.AppSettings["UseDefaultCredentials"]),
                        Credentials           = new NetworkCredential(sender.Address, password)
                    };

                    using (var messege = new MailMessage(sender, receiver)
                    {
                        Body = body,
                        Subject = subject,
                        IsBodyHtml = true
                    })
                    {
                        smtp.Send(messege);
                    }
                }
            }


            // Below Code is For New Note Added

            else
            {
                var    SubmitValue = Request.Form["SavePublish"];
                string fileExtension;
                string DisplayPictureFileName;
                string PreviewFileName;
                if (SubmitValue == "save")
                {
                    // check paid status
                    SellNotesEntity PaidOrNot  = new SellNotesEntity();
                    bool            PaidStatus = PaidOrNot.CheckNoteStatusPaidOrNot(user.IsPaidOrNot);



                    var addSellNoteDetail = new SellNote
                    {
                        Course        = user.SellNote.Course,
                        CourseCode    = user.SellNote.CourseCode,
                        Discription   = user.SellNote.Discription,
                        NumberOfPages = user.SellNote.NumberOfPages,
                        Professor     = user.SellNote.Professor,

                        Title          = user.SellNote.Title,
                        UniversityName = user.SellNote.UniversityName,
                        IsPaid         = PaidStatus,
                        Category       = user.SellNote.Category,
                        Country        = user.SellNote.Country,
                        NoteType       = user.SellNote.NoteType,
                        Status         = Convert.ToInt32(Enums.ReferenceNoteStatus.Draft),
                        ActionedBy     = 3,
                        SellerID       = Convert.ToInt32(Session["ID"]),
                        IsActive       = true,
                        CreatedDate    = DateTime.Now
                    };

                    try
                    {
                        if (user.SellNote.SellingPrice != null)
                        {
                            addSellNoteDetail.SellingPrice = user.SellNote.SellingPrice;
                        }
                        else
                        {
                            addSellNoteDetail.SellingPrice = 0;
                        }
                        db.SellNotes.Add(addSellNoteDetail);
                        db.SaveChanges();
                        int NotesID = addSellNoteDetail.ID;


                        if (DisplayPictureFile != null)
                        {
                            fileExtension = Path.GetExtension(DisplayPictureFile.FileName);
                            fileExtension = fileExtension.ToLower();
                            if (fileExtension == ".jpg" || fileExtension == ".jpeg" || fileExtension == ".png" ||
                                fileExtension == ".JPG" || fileExtension == ".JPEG" || fileExtension == ".PNG")
                            {
                                DisplayPictureFileName           = "DP_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                addSellNoteDetail.DisplayPicture = DisplayPictureFileName;
                                DisplayPictureFileName           = CheckifPathExistForCurrentUser(NotesID) + DisplayPictureFileName;

                                DisplayPictureFile.SaveAs(DisplayPictureFileName);
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("DisplayPictureFile", "Please upload image file of jpg, jpeg, png only");
                                user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                return(View(user));
                            }
                        }

                        if (PreviewFile != null)
                        {
                            fileExtension = Path.GetExtension(PreviewFile.FileName);
                            fileExtension = fileExtension.ToLower();
                            if (fileExtension == ".pdf")
                            {
                                PreviewFileName = "PreviewFile_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                addSellNoteDetail.NotesPreview = PreviewFileName;
                                PreviewFileName = CheckifPathExistForCurrentUser(NotesID) + PreviewFileName;

                                PreviewFile.SaveAs(PreviewFileName);
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("inputAddNotePreview", "Please upload file of pdf only");
                                user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                return(View(user));
                            }
                        }

                        var  FilePathForUploadedPdf = checkifPathExistForNoteAttachment(NotesID);
                        long Length = 0;
                        foreach (HttpPostedFileBase file in UploadedPdfFile)
                        {
                            //Checking file is available to save.
                            if (file != null)
                            {
                                fileExtension = Path.GetExtension(file.FileName);
                                fileExtension = fileExtension.ToLower();
                                if (fileExtension == ".pdf")
                                {
                                    var InputFileName = Path.GetFileNameWithoutExtension(file.FileName);
                                    var attachment    = new SellNoteAttachment()
                                    {
                                        NoteID   = NotesID,
                                        FileName = InputFileName,
                                        FilePath = FilePathForUploadedPdf,
                                        IsActive = true
                                    };
                                    db.SellNoteAttachments.Add(attachment);
                                    db.SaveChanges();
                                    int AttachmentID = attachment.ID;

                                    var UploadedPdfFileName = AttachmentID.ToString() + "_" + InputFileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                    attachment.FileName = UploadedPdfFileName;
                                    var destinationFileLocation = Path.Combine(FilePathForUploadedPdf, UploadedPdfFileName);
                                    file.SaveAs(destinationFileLocation);
                                    Length = Length + file.ContentLength;
                                    db.SaveChanges();
                                }
                                else
                                {
                                    ModelState.AddModelError("inputAdNoteUploadNotes", "Please upload file of pdf only");
                                    user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                    user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                    user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                    return(View(user));
                                }
                            }
                        }

                        addSellNoteDetail.AttachmentSize = FileSizeFormatter.FormatSize(Length);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                else if (SubmitValue == "publish")
                {
                    // check paid status
                    SellNotesEntity PaidOrNot  = new SellNotesEntity();
                    bool            PaidStatus = PaidOrNot.CheckNoteStatusPaidOrNot(user.IsPaidOrNot);

                    var addSellNoteDetail = new SellNote
                    {
                        Course        = user.SellNote.Course,
                        CourseCode    = user.SellNote.CourseCode,
                        Discription   = user.SellNote.Discription,
                        NumberOfPages = user.SellNote.NumberOfPages,
                        Professor     = user.SellNote.Professor,

                        Title          = user.SellNote.Title,
                        UniversityName = user.SellNote.UniversityName,
                        IsPaid         = PaidStatus,
                        Category       = user.SellNote.Category,
                        Country        = user.SellNote.Country,
                        NoteType       = user.SellNote.NoteType,
                        Status         = 4,
                        ActionedBy     = 3,
                        SellerID       = Convert.ToInt32(Session["ID"]),
                        IsActive       = true,
                        CreatedDate    = DateTime.Now,
                        PublishedDate  = DateTime.Now
                    };

                    try
                    {
                        if (user.SellNote.SellingPrice != null)
                        {
                            addSellNoteDetail.SellingPrice = user.SellNote.SellingPrice;
                        }
                        else
                        {
                            addSellNoteDetail.SellingPrice = 0;
                        }
                        db.SellNotes.Add(addSellNoteDetail);
                        db.SaveChanges();
                        int NotesID = addSellNoteDetail.ID;


                        if (DisplayPictureFile != null)
                        {
                            fileExtension = Path.GetExtension(DisplayPictureFile.FileName);
                            fileExtension = fileExtension.ToLower();
                            if (fileExtension == ".jpg" || fileExtension == ".jpeg" || fileExtension == ".png" ||
                                fileExtension == ".JPG" || fileExtension == ".JPEG" || fileExtension == ".PNG")
                            {
                                DisplayPictureFileName           = "DP_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                addSellNoteDetail.DisplayPicture = DisplayPictureFileName;
                                DisplayPictureFileName           = CheckifPathExistForCurrentUser(NotesID) + DisplayPictureFileName;

                                DisplayPictureFile.SaveAs(DisplayPictureFileName);
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("DisplayPictureFile", "Please upload image file of jpg, jpeg, png only");
                                user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                return(View(user));
                            }
                        }

                        if (PreviewFile != null)
                        {
                            fileExtension = Path.GetExtension(PreviewFile.FileName);
                            fileExtension = fileExtension.ToLower();
                            if (fileExtension == ".pdf")
                            {
                                PreviewFileName = "PreviewFile_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                addSellNoteDetail.NotesPreview = PreviewFileName;
                                PreviewFileName = CheckifPathExistForCurrentUser(NotesID) + PreviewFileName;

                                PreviewFile.SaveAs(PreviewFileName);
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("inputAddNotePreview", "Please upload file of pdf only");
                                user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                return(View(user));
                            }
                        }

                        var  FilePathForUploadedPdf = checkifPathExistForNoteAttachment(NotesID);
                        long Length = 0;
                        foreach (HttpPostedFileBase file in UploadedPdfFile)
                        {
                            //Checking file is available to save.
                            if (file != null)
                            {
                                fileExtension = Path.GetExtension(file.FileName);
                                fileExtension = fileExtension.ToLower();
                                if (fileExtension == ".pdf")
                                {
                                    var InputFileName = Path.GetFileNameWithoutExtension(file.FileName);
                                    var attachment    = new SellNoteAttachment()
                                    {
                                        NoteID   = NotesID,
                                        FileName = InputFileName,
                                        FilePath = FilePathForUploadedPdf,
                                        IsActive = true
                                    };
                                    db.SellNoteAttachments.Add(attachment);
                                    db.SaveChanges();
                                    int AttachmentID = attachment.ID;

                                    var UploadedPdfFileName = AttachmentID.ToString() + "_" + InputFileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                                    attachment.FileName = UploadedPdfFileName;
                                    var destinationFileLocation = Path.Combine(FilePathForUploadedPdf, UploadedPdfFileName);
                                    file.SaveAs(destinationFileLocation);
                                    Length = Length + file.ContentLength;
                                    db.SaveChanges();
                                }
                                else
                                {
                                    ModelState.AddModelError("inputAdNoteUploadNotes", "Please upload file of pdf only");
                                    user.NoteCategories = db.NoteCategories.Where(x => x.IsActive == true).ToList();
                                    user.Countries      = db.Countries.Where(x => x.IsActive == true).ToList();
                                    user.NoteTypes      = db.NoteTypes.Where(x => x.IsActive == true).ToList();
                                    return(View(user));
                                }
                            }
                        }
                        addSellNoteDetail.AttachmentSize = FileSizeFormatter.FormatSize(Length);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }


                    db.SaveChanges();
                    int  id       = Convert.ToInt32(Session["ID"]);
                    User SendMail = db.Users.Where(x => x.ID == id).FirstOrDefault();

                    // Mail Sending Code
                    var sender   = new MailAddress(ConstantStrings.supportEmail, ConstantStrings.supportName);
                    var receiver = new MailAddress("*****@*****.**", "Admin");
                    var password = ConstantStrings.supportPassword;
                    var body     = string.Empty;
                    var subject  = SendMail.FirstName + " sent his note for review";

                    using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplates/PublishNoteNotification.html")))
                    {
                        body = reader.ReadToEnd();
                    }
                    body = body.Replace("{SellerName}", SendMail.FirstName);
                    body = body.Replace("{NoteTitle}", addSellNoteDetail.Title);

                    var smtp = new SmtpClient
                    {
                        Host                  = ConfigurationManager.AppSettings["Host"],
                        Port                  = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
                        EnableSsl             = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]),
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = Convert.ToBoolean(ConfigurationManager.AppSettings["UseDefaultCredentials"]),
                        Credentials           = new NetworkCredential(sender.Address, password)
                    };

                    using (var messege = new MailMessage(sender, receiver)
                    {
                        Body = body,
                        Subject = subject,
                        IsBodyHtml = true
                    })
                    {
                        smtp.Send(messege);
                    }
                }
            }
            return(RedirectToAction("Index", "Dashboard"));
        }