Example #1
0
        public ActionResult NotesDetail(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();

            return(View(sellrnote));
        }
        public void SendEmailToAdmin(string support, string password, string emailID, int id)
        {
            SellerNote seller = dbobj.SellerNotes.Where(x => x.Id == id).FirstOrDefault();

            User   user1             = dbobj.Users.Where(x => x.ID == seller.SellerID).FirstOrDefault();
            var    fromEmail         = new MailAddress(support, "Notemarketplace");
            var    toEmail           = new MailAddress(emailID);
            var    fromEmailPassword = password; // Replace with actual password
            string subject           = user1.FirstName + " " + "Sent his note for review";
            string body = "Hello  Admin," + "<br/>";

            body += "<br/>We want to inform you that" + " " + user1.FirstName + "  Sent his note";
            body += "<br/> " + seller.Title + " " + "for review." + "Please look at the notes and take required actions.";
            body += "<br/><br/>Regards,<br/>";
            body += "Notes marketplace";
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromEmail.Address, fromEmailPassword)
            };

            using (var message = new MailMessage(fromEmail, toEmail)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
                smtp.Send(message);
        }
        public void SendEmailtoBuyer(string emailID, int noteid, string support, string password)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Where(x => x.Id == noteid).FirstOrDefault();
            User       objuser   = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();

            User user = dbobj.Users.Where(x => x.EmailId == emailID).FirstOrDefault();

            var    fromEmail         = new MailAddress(support, "Notemarketplace");
            var    toEmail           = new MailAddress(emailID);
            var    fromEmailPassword = password; // Replace with actual password
            string subject           = objuser.FirstName + " " + "Allows you to downnload a note";
            string body = "Hello " + " " + user.FirstName + "<br/>";

            body += "<br/>We would like to inform you that" + " " + objuser.FirstName + "  Allows you to downnload a note.<br/>" +
                    "Please login and see my Download tabs to download particular note<br/>";
            body += "<br/><br/>Regards,<br/>";
            body += "Notes marketplace";
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromEmail.Address, fromEmailPassword)
            };

            using (var message = new MailMessage(fromEmail, toEmail)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
                smtp.Send(message);
        }
Example #4
0
        public void SendEmailtoSellerforUnPublish(string emailID, int id, string support, string password)
        {
            User       objuser           = dbobj.Users.Where(x => x.EmailId == emailID).FirstOrDefault();
            SellerNote objseller         = dbobj.SellerNotes.Where(x => x.SellerID == objuser.ID && x.Id == id).FirstOrDefault();
            var        fromEmail         = new MailAddress(support, "Notemarketplace");
            var        toEmail           = new MailAddress(emailID);
            var        fromEmailPassword = password; // Replace with actual password
            string     subject           = "Sorry! We need to remove your notes from our portal.";
            string     body = "Hello " + " " + objuser.FirstName + "<br/>";

            body += "<br/>We want like to inform you that, your note" + " " + objseller.Title + " " + " has been removed from the portal.<br/>" +
                    "Please find our remarks as below-<br/>"
                    + objseller.AdminRemarks;
            ;
            body += "<br/><br/>Regards,<br/>";
            body += "Notes marketplace";
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromEmail.Address, fromEmailPassword)
            };

            using (var message = new MailMessage(fromEmail, toEmail)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
                smtp.Send(message);
        }
        public ActionResult ReturnSoldNote(int NoteID)
        {
            SellerNote notedetail = db.SellerNotes.Where(m => m.id == NoteID).SingleOrDefault();
            var        user       = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).SingleOrDefault();

            var attechment = db.SellerNotesAttechments.Where(m => m.NoteID == notedetail.id).SingleOrDefault();

            if (user.id == notedetail.SellerID)
            {
                FileDownload obj        = new FileDownload();
                var          ListOfFile = obj.GetFile(attechment.FilePath).ToList();
                using (var memoryStream = new MemoryStream())
                {
                    using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        for (int i = 0; i < ListOfFile.Count(); i++)
                        {
                            zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName);
                        }
                    }
                    return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip"));
                }
            }

            return(null);
        }
Example #6
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is Booking other &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((Version == null && other.Version == null) || (Version?.Equals(other.Version) == true)) &&
                   ((Status == null && other.Status == null) || (Status?.Equals(other.Status) == true)) &&
                   ((CreatedAt == null && other.CreatedAt == null) || (CreatedAt?.Equals(other.CreatedAt) == true)) &&
                   ((UpdatedAt == null && other.UpdatedAt == null) || (UpdatedAt?.Equals(other.UpdatedAt) == true)) &&
                   ((StartAt == null && other.StartAt == null) || (StartAt?.Equals(other.StartAt) == true)) &&
                   ((LocationId == null && other.LocationId == null) || (LocationId?.Equals(other.LocationId) == true)) &&
                   ((CustomerId == null && other.CustomerId == null) || (CustomerId?.Equals(other.CustomerId) == true)) &&
                   ((CustomerNote == null && other.CustomerNote == null) || (CustomerNote?.Equals(other.CustomerNote) == true)) &&
                   ((SellerNote == null && other.SellerNote == null) || (SellerNote?.Equals(other.SellerNote) == true)) &&
                   ((AppointmentSegments == null && other.AppointmentSegments == null) || (AppointmentSegments?.Equals(other.AppointmentSegments) == true)));
        }
Example #7
0
        public ActionResult Clone(int id)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Find(id);

            if (sellrnote != null && sellrnote.Referencedata.value == "rejected")
            {
                sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "draft").Select(x => x.Id).FirstOrDefault();
            }
            dbobj.Entry(sellrnote).State = EntityState.Modified;
            dbobj.SaveChanges();
            return(RedirectToAction("Dashboard", "Notes"));
        }
Example #8
0
        public ActionResult Download(int Id)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Find(Id);

            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                MemoryStream output = new MemoryStream();
                zip.Save(output);
                return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
            }
        }
Example #9
0
        public ActionResult InReview(int id)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Find(id);

            if (sellrnote != null && sellrnote.Referencedata.value == "submitted for review")
            {
                sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "in review").Select(x => x.Id).FirstOrDefault();
            }
            dbobj.Entry(sellrnote).State = EntityState.Modified;
            dbobj.SaveChanges();
            return(RedirectToAction("AdminDashboard", "Admin"));
        }
Example #10
0
        public ActionResult Download(int Id)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Where(x => x.Id == Id && x.Referencedata.value == "published").FirstOrDefault();

            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                MemoryStream output = new MemoryStream();
                zip.Save(output);
                return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
            }
            return(View());
        }
Example #11
0
        public ActionResult Approve(int id)
        {
            var        Emailid   = User.Identity.Name.ToString();
            User       user      = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            SellerNote sellrnote = dbobj.SellerNotes.Find(id);

            if (sellrnote != null && (sellrnote.Referencedata.value == "submitted for review" || sellrnote.Referencedata.value == "in review" || sellrnote.Referencedata.value == "rejected"))
            {
                sellrnote.Status        = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "published").Select(x => x.Id).FirstOrDefault();
                sellrnote.ActionedBy    = user.ID;
                sellrnote.Publisheddate = DateTime.Now;
            }
            dbobj.Entry(sellrnote).State = EntityState.Modified;
            dbobj.SaveChanges();
            return(RedirectToAction("AdminDashboard", "Admin"));
        }
Example #12
0
        public ActionResult DeleteDraft(int id)
        {
            // get notes using id
            SellerNote note = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true).FirstOrDefault();

            // if note is not found
            if (note == null)
            {
                return(HttpNotFound());
            }
            // get attachement files using note id
            IEnumerable <SellerNotesAttachment> noteattachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == id && x.IsActive == true).ToList();

            // if noteattachement count is 0
            if (noteattachement.Count() == 0)
            {
                return(HttpNotFound());
            }
            // filepaths for note and note attachements
            string notefolderpath           = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID);
            string noteattachmentfolderpath = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements");

            // get directory
            DirectoryInfo notefolder            = new DirectoryInfo(notefolderpath);
            DirectoryInfo attachementnotefolder = new DirectoryInfo(noteattachmentfolderpath);

            // empty directory
            EmptyFolder(attachementnotefolder);
            EmptyFolder(notefolder);
            // delete directory
            Directory.Delete(notefolderpath);

            // remove note from database
            _dbcontext.SellerNotes.Remove(note);

            // remove attachement from database
            foreach (var item in noteattachement)
            {
                SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.ID == item.ID).FirstOrDefault();
                _dbcontext.SellerNotesAttachments.Remove(attachement);
            }

            // save changes
            _dbcontext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
        public ActionResult Editnote(int Id, UserSellernotes editnote, string SAVE)
        {
            SellerNote sellrnote = dbobj.SellerNotes.Find(Id);

            sellrnote.Title          = editnote.Title;
            sellrnote.Category       = editnote.Category;
            sellrnote.Description    = editnote.Description;
            sellrnote.IsPaid         = editnote.IsPaid;
            sellrnote.NoteType       = editnote.NoteType;
            sellrnote.NumberofPages  = editnote.NumberofPages;
            sellrnote.UniversityName = editnote.UniversityName;
            sellrnote.Country        = editnote.Country;
            sellrnote.Course         = editnote.Course;
            sellrnote.CourseCode     = editnote.CourseCode;
            sellrnote.Professor      = editnote.Professor;
            sellrnote.SellingPrice   = editnote.SellingPrice;
            sellrnote.ModifiedDate   = DateTime.Now;
            sellrnote.IsActive       = true;

            if (SAVE == "save")
            {
                sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "draft").Select(x => x.Id).FirstOrDefault();
            }
            else
            {
                sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "submitted for review").Select(x => x.Id).FirstOrDefault();
                SystemConfiguration system  = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault();
                SystemConfiguration system1 = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault();
                SystemConfiguration system2 = dbobj.SystemConfigurations.Where(x => x.Key == "EmailAddress").FirstOrDefault();
                SendEmailToAdmin(system.Value, system1.Value, system2.Value, Id);
            }

            dbobj.Entry(sellrnote).State = EntityState.Modified;
            dbobj.SaveChanges();
            if (sellrnote == null)
            {
                return(HttpNotFound());
            }

            ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
            ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
            ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
            return(RedirectToAction("Dashboard", "Notes"));

            return(View(sellrnote));
        }
Example #14
0
        public ActionResult EditNotes(int id)
        {
            // get logged in user
            User user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get note
            SellerNote note = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true && x.SellerID == user.UserID).FirstOrDefault();
            // get note attachement
            SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == id).FirstOrDefault();

            if (note != null)
            {
                // create object of edit note viewmodel
                EditNotesViewModel viewModel = new EditNotesViewModel
                {
                    ID               = note.ID,
                    NoteID           = note.ID,
                    Title            = note.Title,
                    Category         = note.Category,
                    Picture          = note.DisplayPicture,
                    Note             = attachement.FilePath,
                    NumberofPages    = note.NumberOfPages,
                    Description      = note.Description,
                    NoteType         = note.NoteType,
                    UniversityName   = note.UniversityName,
                    Course           = note.Course,
                    CourseCode       = note.CourseCode,
                    Country          = note.Country,
                    Professor        = note.Professor,
                    IsPaid           = note.IsPaid,
                    SellingPrice     = note.SellingPrice,
                    Preview          = note.NotesPreview,
                    NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList()
                };

                // return viewmodel to edit notes page
                return(View(viewModel));
            }
            else
            {
                // if note not found
                return(HttpNotFound());
            }
        }
        public ActionResult AllowDownload(int id, int buyerid)
        {
            //bool Status = false;
            {
                var v = dbobj.Downloads.Where(a => a.NoteId == id && a.isSellerhasAllowedDownloaded == false && a.downloader == buyerid).FirstOrDefault();
                SellerNotesAttachement sellernote    = dbobj.SellerNotesAttachements.Where(x => x.NoteID == id).FirstOrDefault();
                SellerNote             objsellernote = dbobj.SellerNotes.Where(x => x.Id == id).FirstOrDefault();
                if (v != null)
                {
                    v.isSellerhasAllowedDownloaded = true;
                    v.AttachmentPath = sellernote.FilePath;
                    v.ModifiedBy     = objsellernote.SellerID;
                    dbobj.SaveChanges();
                }

                User user = dbobj.Users.Where(x => x.ID == v.downloader).FirstOrDefault();
                SendEmailtoBuyer(user.EmailId.ToString(), v.NoteId);
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }
Example #16
0
        public ActionResult Unpublish(int id, string remarks)
        {
            var                 Emailid   = User.Identity.Name.ToString();
            User                user      = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            SellerNote          sellrnote = dbobj.SellerNotes.Find(id);
            SystemConfiguration system    = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault();
            SystemConfiguration system1   = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault();

            if (sellrnote != null && (sellrnote.Referencedata.value == "published"))
            {
                User objuser = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();
                sellrnote.Status       = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "removed").Select(x => x.Id).FirstOrDefault();
                sellrnote.ActionedBy   = user.ID;
                sellrnote.ModifiedDate = DateTime.Now;
                sellrnote.AdminRemarks = remarks;
                SendEmailtoSellerforUnPublish(objuser.EmailId.ToString(), id, system.Value, system1.Value);
            }
            dbobj.Entry(sellrnote).State = EntityState.Modified;
            dbobj.SaveChanges();
            return(RedirectToAction("AdminDashboard", "Admin"));
        }
Example #17
0
        public ActionResult ReportanIssue(int id, string remarks)
        {
            var        Emailid     = User.Identity.Name.ToString();
            User       user        = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            SellerNote sellrnote   = dbobj.SellerNotes.Where(x => x.Id == id).FirstOrDefault();
            Download   objdownload = dbobj.Downloads.Where(x => x.NoteId == id).FirstOrDefault();
            SellerNotesReportedIssue reportedIssue = dbobj.SellerNotesReportedIssues.Where(x => x.NoteId == sellrnote.Id && x.ReportedByid == user.ID).FirstOrDefault();

            if (reportedIssue != null)
            {
                reportedIssue.Remarks            = remarks;
                reportedIssue.Modifieddate       = DateTime.Now;
                reportedIssue.ModifiedBy         = user.ID;
                dbobj.Entry(reportedIssue).State = EntityState.Modified;
                dbobj.SaveChanges();
            }
            else
            {
                SellerNotesReportedIssue objseller1 = new SellerNotesReportedIssue
                {
                    NoteId            = sellrnote.Id,
                    Remarks           = remarks,
                    ReportedByid      = user.ID,
                    againstDownloadId = objdownload.Id,
                    CreatedBy         = objdownload.downloader,
                    CreatedDate       = DateTime.Now,
                    IsActive          = true
                };
                dbobj.SellerNotesReportedIssues.Add(objseller1);
                dbobj.SaveChanges();
            }
            SystemConfiguration system  = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault();
            SystemConfiguration system1 = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault();
            SystemConfiguration system2 = dbobj.SystemConfigurations.Where(x => x.Key == "EmailAddress").FirstOrDefault();

            SendEmailtoAdmin(system.Value, system1.Value, system2.Value, id);
            return(RedirectToAction("Dashboard", "Notes"));
        }
Example #18
0
        public ActionResult Review(int id, string comments, int rate)
        {
            Download          objdownload = dbobj.Downloads.Where(x => x.NoteId == id).FirstOrDefault();
            var               Emailid     = User.Identity.Name.ToString();
            User              user        = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            SellerNote        sellrnote   = dbobj.SellerNotes.Where(x => x.Id == id).FirstOrDefault();
            SellerNotesReview objseller   = dbobj.SellerNotesReviews.Where(x => x.NoteId == sellrnote.Id && x.ReviewedByid == user.ID).FirstOrDefault();

            if (objseller != null)
            {
                objseller.Ratings            = rate;
                objseller.Comments           = comments;
                objseller.ModifiedBy         = user.ID;
                objseller.Modifieddate       = DateTime.Now;
                dbobj.Entry(objseller).State = EntityState.Modified;
                dbobj.SaveChanges();
            }
            else
            {
                SellerNotesReview objseller1 = new SellerNotesReview
                {
                    NoteId             = sellrnote.Id,
                    Ratings            = rate,
                    Comments           = comments,
                    ReviewedByid       = user.ID,
                    AgainstDownloadsId = objdownload.Id,
                    CreatedBy          = objdownload.downloader,
                    CreatedDate        = DateTime.Now,
                    IsActive           = true
                };
                dbobj.SellerNotesReviews.Add(objseller1);
                dbobj.SaveChanges();
            }

            return(RedirectToAction("Dashboard", "Notes"));
        }
Example #19
0
        public ActionResult Editnote(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            UserSellernotes        editnote = new UserSellernotes
            {
                ID             = sellrnote.Id,
                Title          = sellrnote.Title,
                Category       = sellrnote.Category,
                Description    = sellrnote.Description,
                IsPaid         = sellrnote.IsPaid,
                NoteType       = sellrnote.NoteType,
                NumberofPages  = sellrnote.NumberofPages,
                UniversityName = sellrnote.UniversityName,
                Country        = sellrnote.Country,
                Course         = sellrnote.Course,
                CourseCode     = sellrnote.CourseCode,
                Professor      = sellrnote.Professor,
                SellingPrice   = sellrnote.SellingPrice,
                CreatedDate    = sellrnote.CreatedDate
            };

            if (sellrnote == null)
            {
                return(HttpNotFound());
            }

            ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
            ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
            ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
            return(View(editnote));
        }
Example #20
0
        public ActionResult addnotes(UserSellernotes note)
        {
            if (ModelState.IsValid)
            {
                var           Emailid       = User.Identity.Name.ToString();
                User          user          = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
                Referencedata rf            = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status").FirstOrDefault();
                SellerNote    objsellernote = new SellerNote
                {
                    SellerID       = user.ID,
                    Status         = rf.Id,
                    Title          = note.Title,
                    Category       = note.Category,
                    NoteType       = note.NoteType,
                    Professor      = note.Professor,
                    Description    = note.Description,
                    IsPaid         = note.IsPaid,
                    NumberofPages  = note.NumberofPages,
                    UniversityName = note.UniversityName,
                    Country        = note.Country,
                    Course         = note.Course,
                    CourseCode     = note.CourseCode,
                    SellingPrice   = note.SellingPrice,
                    CreatedDate    = DateTime.Now,
                    IsActive       = true
                };
                dbobj.SellerNotes.Add(objsellernote);
                dbobj.SaveChanges();
                var noteID = objsellernote.Id;
                //display picture
                //generate path to store image
                string storepath = Path.Combine(Server.MapPath("/UploadFiles/" + user.ID), noteID.ToString());
                //check for directory, if not exist ,then create it
                if (!Directory.Exists(storepath))
                {
                    Directory.CreateDirectory(storepath);
                }
                if (note.DisplayPicture != null && note.DisplayPicture.ContentLength > 0)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(note.DisplayPicture.FileName);
                    string extension = Path.GetExtension(note.DisplayPicture.FileName);
                    _FileName = "DP_" + DateTime.Now.ToString("yymmssfff") + extension;
                    string finalpath = Path.Combine(storepath, _FileName);
                    note.DisplayPicture.SaveAs(finalpath);
                    objsellernote.DisplayPicture = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName);
                    dbobj.SaveChanges();
                }
                else
                {
                    objsellernote.DisplayPicture = "/System Configuration/DefaultImage/4.jpg";
                    dbobj.SaveChanges();
                }
                //upload notes
                string storeuploadpath = Path.Combine(storepath, "Attachments");
                //check for directory, if not exist ,then create it
                if (!Directory.Exists(storeuploadpath))
                {
                    Directory.CreateDirectory(storeuploadpath);
                }
                SellerNotesAttachement objsellernoteattachment = new SellerNotesAttachement
                {
                    NoteID      = noteID,
                    IsActive    = true,
                    CreatedBy   = user.ID,
                    Createddate = DateTime.Now
                };
                //
                int count = 1;
                var UploadnoteFilePath = "";
                var UploadnoteFileName = "";
                foreach (var File in note.UploadNotes)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(File.FileName);
                    string extension = Path.GetExtension(File.FileName);
                    _FileName = "Attachment" + count + "_" + DateTime.Now.ToString("ddmyyyy") + extension;
                    string finalpath = Path.Combine(storeuploadpath, _FileName);
                    File.SaveAs(finalpath);
                    UploadnoteFileName += _FileName + ";";
                    UploadnoteFilePath += Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/Attachment/"), _FileName);
                    count++;
                }
                objsellernoteattachment.FileName = UploadnoteFileName;
                objsellernoteattachment.FilePath = UploadnoteFilePath;
                dbobj.SellerNotesAttachements.Add(objsellernoteattachment);
                dbobj.SaveChanges();
                //notes preview
                if (note.IsPaid == true)
                {
                    if (note.NotesPreview == null)
                    {
                        ViewBag.ErrorMessage = "plz upload preview";
                        ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
                        ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
                        ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
                        return(View(note));
                    }
                }

                if (note.NotesPreview != null && note.NotesPreview.ContentLength > 0)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(note.NotesPreview.FileName);
                    string extension = Path.GetExtension(note.NotesPreview.FileName);
                    _FileName = "Preview_" + DateTime.Now.ToString("yymmssfff") + extension;
                    string finalpath = Path.Combine(storepath, _FileName);
                    note.NotesPreview.SaveAs(finalpath);
                    objsellernote.NotesPreview = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName);
                    dbobj.SaveChanges();
                }
                return(RedirectToAction("Dashboard", "Notes"));
            }

            ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
            ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
            ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
            return(View(note));
        }
Example #21
0
        public ActionResult AddNotes(AddNotesViewModel addnotesviewmodel)
        {
            // check if upload note is null or not
            if (addnotesviewmodel.UploadNotes[0] == null)
            {
                ModelState.AddModelError("UploadNotes", "This field is required");
                addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                return(View(addnotesviewmodel));
            }
            // check and raise error for note preview is null for paid notes
            if (addnotesviewmodel.IsPaid == true && addnotesviewmodel.NotesPreview == null)
            {
                ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                return(View(addnotesviewmodel));
            }

            foreach (HttpPostedFileBase file in addnotesviewmodel.UploadNotes)
            {
                if (!System.IO.Path.GetExtension(file.FileName).Equals(".pdf"))
                {
                    ModelState.AddModelError("UploadNotes", "Only PDF Format is allowed");
                    addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                    addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                    addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                    return(View(addnotesviewmodel));
                }
            }


            // check model state
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNote sellernotes = new SellerNote();

                User user = _dbcontext.Users.FirstOrDefault(x => x.EmailID == User.Identity.Name);

                sellernotes.SellerID       = user.UserID;
                sellernotes.Title          = addnotesviewmodel.Title.Trim();
                sellernotes.Status         = _dbcontext.ReferenceDatas.Where(x => x.Value.ToLower() == "draft").Select(x => x.ID).FirstOrDefault();
                sellernotes.Category       = addnotesviewmodel.Category;
                sellernotes.NoteType       = addnotesviewmodel.NoteType;
                sellernotes.NumberOfPages  = addnotesviewmodel.NumberofPages;
                sellernotes.Description    = addnotesviewmodel.Description.Trim();
                sellernotes.UniversityName = addnotesviewmodel.UniversityName.Trim();
                sellernotes.Country        = addnotesviewmodel.Country;
                sellernotes.Course         = addnotesviewmodel.Course.Trim();
                sellernotes.CourseCode     = addnotesviewmodel.CourseCode.Trim();
                sellernotes.Professor      = addnotesviewmodel.Professor.Trim();
                sellernotes.IsPaid         = addnotesviewmodel.IsPaid;
                if (sellernotes.IsPaid)
                {
                    sellernotes.SellingPrice = addnotesviewmodel.SellingPrice;
                }
                else
                {
                    sellernotes.SellingPrice = 0;
                }
                sellernotes.CreatedDate = DateTime.Now;
                sellernotes.CreatedBy   = user.UserID;
                sellernotes.IsActive    = true;

                // add note in database and save
                _dbcontext.SellerNotes.Add(sellernotes);
                _dbcontext.SaveChanges();

                // get seller note
                sellernotes = _dbcontext.SellerNotes.Find(sellernotes.ID);

                // if display picture is not null then save picture into directory and directory path into database
                if (addnotesviewmodel.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(addnotesviewmodel.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    addnotesviewmodel.DisplayPicture.SaveAs(displaypicturefilepath);
                }

                // if note preview is not null then save picture into directory and directory path into database
                if (addnotesviewmodel.NotesPreview != null)
                {
                    string notespreviewfilename = System.IO.Path.GetFileName(addnotesviewmodel.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    addnotesviewmodel.NotesPreview.SaveAs(notespreviewfilepath);
                }

                // update note preview path and display picture path and save changes
                _dbcontext.SellerNotes.Attach(sellernotes);
                _dbcontext.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true;
                _dbcontext.Entry(sellernotes).Property(x => x.NotesPreview).IsModified   = true;
                _dbcontext.SaveChanges();

                // attachement files
                foreach (HttpPostedFileBase file in addnotesviewmodel.UploadNotes)
                {
                    // check if file is null or not
                    if (file != null)
                    {
                        // save file in directory
                        string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                        string notesattachementpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/Attachements/";
                        CreateDirectoryIfMissing(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

                        // create object of sellernotesattachement
                        SellerNotesAttachment notesattachements = new SellerNotesAttachment
                        {
                            NoteID      = sellernotes.ID,
                            FileName    = notesattachementfilename,
                            FilePath    = notesattachementpath,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = user.UserID,
                            IsActive    = true
                        };

                        // save seller notes attachement
                        _dbcontext.SellerNotesAttachments.Add(notesattachements);
                        _dbcontext.SaveChanges();
                    }
                }

                return(RedirectToAction("Dashboard", "SellYourNotes"));
            }
            // if model state is not valid
            else
            {
                // create object of addnotesviewmodel
                AddNotesViewModel viewModel = new AddNotesViewModel
                {
                    NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList()
                };

                return(View(viewModel));
            }
        }
Example #22
0
        public override int GetHashCode()
        {
            int hashCode = 219005029;

            if (Id != null)
            {
                hashCode += Id.GetHashCode();
            }

            if (Version != null)
            {
                hashCode += Version.GetHashCode();
            }

            if (Status != null)
            {
                hashCode += Status.GetHashCode();
            }

            if (CreatedAt != null)
            {
                hashCode += CreatedAt.GetHashCode();
            }

            if (UpdatedAt != null)
            {
                hashCode += UpdatedAt.GetHashCode();
            }

            if (StartAt != null)
            {
                hashCode += StartAt.GetHashCode();
            }

            if (LocationId != null)
            {
                hashCode += LocationId.GetHashCode();
            }

            if (CustomerId != null)
            {
                hashCode += CustomerId.GetHashCode();
            }

            if (CustomerNote != null)
            {
                hashCode += CustomerNote.GetHashCode();
            }

            if (SellerNote != null)
            {
                hashCode += SellerNote.GetHashCode();
            }

            if (AppointmentSegments != null)
            {
                hashCode += AppointmentSegments.GetHashCode();
            }

            return(hashCode);
        }
        public ActionResult Correction(int NoteID)
        {
            var user = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).Select(m => m.id).SingleOrDefault();
            var addNotesCategoriesTypeCountry = db.SellerNotes.Where(m => m.id == NoteID).SingleOrDefault();
            var noteDetail = new SellerNote();

            noteDetail.Title          = addNotesCategoriesTypeCountry.Title;
            noteDetail.Category       = addNotesCategoriesTypeCountry.Category;
            noteDetail.Country        = addNotesCategoriesTypeCountry.Country;
            noteDetail.Course         = addNotesCategoriesTypeCountry.Course;
            noteDetail.CourseCode     = addNotesCategoriesTypeCountry.CourseCode;
            noteDetail.SellerID       = user;
            noteDetail.CreatedBy      = user;
            noteDetail.CreatedDate    = DateTime.Now;
            noteDetail.Description    = addNotesCategoriesTypeCountry.Description;
            noteDetail.Status         = 1;
            noteDetail.IsPaid         = addNotesCategoriesTypeCountry.IsPaid;
            noteDetail.SellingPrice   = addNotesCategoriesTypeCountry.SellingPrice;
            noteDetail.NumberOfPages  = addNotesCategoriesTypeCountry.NumberOfPages;
            noteDetail.UniversityName = addNotesCategoriesTypeCountry.UniversityName;
            noteDetail.Professor      = addNotesCategoriesTypeCountry.Professor;
            //noteDetail.DisplayPicture = addNotesCategoriesTypeCountry.DisplayPicture;
            //noteDetail.NotesPreview = addNotesCategoriesTypeCountry.NotesPreview;
            db.SellerNotes.Add(noteDetail);
            db.SaveChanges();
            string FilePath = "~/Membere/" + user + "/" + noteDetail.id + "/";

            Directory.CreateDirectory(Server.MapPath(FilePath));
            if (addNotesCategoriesTypeCountry.DisplayPicture != null)
            {
                FileInfo IMGFile       = new FileInfo(Server.MapPath(addNotesCategoriesTypeCountry.DisplayPicture));
                string   UploadPathIMG = Path.Combine(Server.MapPath(FilePath), IMGFile.Name);
                noteDetail.DisplayPicture = FilePath + IMGFile.Name;
                IMGFile.CopyTo(UploadPathIMG, true);
            }
            if (addNotesCategoriesTypeCountry.NotesPreview != null)
            {
                FileInfo priviewFile       = new FileInfo(Server.MapPath(addNotesCategoriesTypeCountry.NotesPreview));
                string   uploadPathPreview = Path.Combine(Server.MapPath(FilePath), priviewFile.Name);
                noteDetail.NotesPreview = FilePath + priviewFile.Name;
                priviewFile.CopyTo(uploadPathPreview, true);
            }
            db.SellerNotes.Attach(noteDetail);
            db.Entry(noteDetail).Property(m => m.DisplayPicture).IsModified = true;
            db.Entry(noteDetail).Property(m => m.NotesPreview).IsModified   = true;
            db.SaveChanges();


            var oldNote         = db.SellerNotesAttechments.Where(m => m.NoteID == addNotesCategoriesTypeCountry.id).SingleOrDefault();
            var notesAttechment = new SellerNotesAttechment();

            string AttachmentPath       = "~/Membere/" + user + "/" + noteDetail.id + "/Attachment/";
            string UploadPathAttachment = Server.MapPath(AttachmentPath);
            bool   isPathExists         = Directory.Exists(UploadPathAttachment);

            if (!isPathExists)
            {
                Directory.CreateDirectory(UploadPathAttachment);
            }

            string[] oldAttachmentFiles = Directory.GetFiles(Server.MapPath(oldNote.FilePath));
            foreach (string oldFile in oldAttachmentFiles)
            {
                FileInfo oldFileinfo = new FileInfo(oldFile);
                string   destination = Path.Combine(UploadPathAttachment, oldFileinfo.Name);
                oldFileinfo.CopyTo(destination, true);
            }
            notesAttechment.NoteID      = noteDetail.id;
            notesAttechment.FileName    = oldNote.FileName;
            notesAttechment.FilePath    = AttachmentPath;
            notesAttechment.CreatedBy   = user;
            notesAttechment.CreatedDate = DateTime.Now;
            notesAttechment.IsActive    = true;
            db.SellerNotesAttechments.Add(notesAttechment);
            db.SaveChanges();


            return(RedirectToAction("MyRejectedNotes", "User"));
        }
        public ActionResult Download(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Where(x => x.Id == Id && x.Referencedata.value == "published").FirstOrDefault();
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            NoteCategory           notecategory            = dbobj.NoteCategories.Where(x => x.Id == sellrnote.Category).FirstOrDefault();
            var      Emailid = User.Identity.Name.ToString();
            User     user    = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            Download dwln    = dbobj.Downloads.Where(x => x.NoteId == Id && x.downloader == user.ID).FirstOrDefault();

            if (dwln != null)
            {
                dwln.ModifiedBy         = user.ID;
                dwln.ModifiedDate       = DateTime.Now;
                dbobj.Entry(dwln).State = EntityState.Modified;
                dbobj.SaveChanges();
            }

            else
            {
                if (sellrnote.IsPaid == false)
                {
                    Download download = new Download
                    {
                        NoteId     = sellrnote.Id,
                        Seller     = sellrnote.SellerID,
                        downloader = user.ID,
                        isSellerhasAllowedDownloaded = true,
                        AttachmentPath           = objsellernoteattachment.FilePath,
                        IsAttachmentDownloaded   = true,
                        AttachmentDownloadedDate = DateTime.Now,
                        Ispaid         = sellrnote.IsPaid,
                        PurchasedPrice = sellrnote.SellingPrice,
                        NoteTitle      = sellrnote.Title,
                        NoteCategory   = notecategory.name,
                        Createddate    = DateTime.Now,
                        CreatedBy      = user.ID,

                        isActive = true
                    };
                    dbobj.Downloads.Add(download);
                    dbobj.SaveChanges();
                    using (ZipFile zip = new ZipFile())
                    {
                        zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                        MemoryStream output = new MemoryStream();
                        zip.Save(output);
                        return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
                    }
                }

                else
                {
                    User objuser = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();
                    SystemConfiguration system  = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault();
                    SystemConfiguration system1 = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault();


                    SendEmailtoSeller(objuser.EmailId.ToString(), system.Value, system1.Value);
                    Download download = new Download
                    {
                        NoteId     = sellrnote.Id,
                        Seller     = sellrnote.SellerID,
                        downloader = user.ID,
                        isSellerhasAllowedDownloaded = false,
                        AttachmentDownloadedDate     = DateTime.Now,
                        Ispaid         = sellrnote.IsPaid,
                        PurchasedPrice = sellrnote.SellingPrice,
                        NoteTitle      = sellrnote.Title,
                        NoteCategory   = notecategory.name,
                        Createddate    = DateTime.Now,
                        CreatedBy      = user.ID,
                        ModifiedBy     = user.ID,
                        isActive       = true
                    };
                    dbobj.Downloads.Add(download);
                    dbobj.SaveChanges();
                }
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }
        public ActionResult DownloadAttechment(int NoteID)
        {
            SellerNote notedetail = db.SellerNotes.Where(m => m.id == NoteID).SingleOrDefault();
            var        user       = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).SingleOrDefault();
            var        attechment = db.SellerNotesAttechments.Where(m => m.NoteID == notedetail.id).SingleOrDefault();

            if (TempData.ContainsKey("returnFile"))
            {
                TempData.Remove("returnFile");
                FileDownload obj        = new FileDownload();
                var          ListOfFile = obj.GetFile(attechment.FilePath).ToList();
                using (var memoryStream = new MemoryStream())
                {
                    using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        for (int i = 0; i < ListOfFile.Count(); i++)
                        {
                            zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName);
                        }
                    }
                    return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip"));
                }
            }
            var alreadyDownloadedUser = db.Downloads.Where(m => m.NoteID == notedetail.id && m.Downloader == user.id && (m.IsPaid == false || (m.IsPaid == true && m.IsAttechmentDownloaded == true))).SingleOrDefault();

            if (alreadyDownloadedUser != null)
            {
                alreadyDownloadedUser.ModifiedBy   = user.id;
                alreadyDownloadedUser.ModifiedDate = DateTime.Now;
                db.Downloads.Attach(alreadyDownloadedUser);
                db.Entry(alreadyDownloadedUser).State = EntityState.Modified;

                db.SaveChanges();
                FileDownload obj        = new FileDownload();
                var          ListOfFile = obj.GetFile(attechment.FilePath).ToList();
                using (var memoryStream = new MemoryStream())
                {
                    using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        for (int i = 0; i < ListOfFile.Count(); i++)
                        {
                            zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName);
                        }
                    }
                    return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip"));
                }
            }

            var AllowedpaidUserForDownload = db.Downloads.Where(m => m.NoteID == notedetail.id && m.Downloader == user.id && m.IsPaid == true && m.IsAttechmentDownloaded == false && m.IsSellerHasAllowedDownload == true).SingleOrDefault();

            if (AllowedpaidUserForDownload != null)
            {
                AllowedpaidUserForDownload.PurchasedPrice           = notedetail.SellingPrice;
                AllowedpaidUserForDownload.AttechmentPath           = attechment.FilePath;
                AllowedpaidUserForDownload.IsAttechmentDownloaded   = true;
                AllowedpaidUserForDownload.AttechmentDownloadedDate = DateTime.Now;
                AllowedpaidUserForDownload.ModifiedBy   = user.id;
                AllowedpaidUserForDownload.ModifiedDate = DateTime.Now;
                db.Downloads.Attach(AllowedpaidUserForDownload);
                db.Entry(AllowedpaidUserForDownload).State = EntityState.Modified;
                db.SaveChanges();
            }
            TempData["Reload"] = NoteID;

            return(RedirectToAction("MyDonwloads", "User"));
        }
        public ActionResult CloneNote(int id)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            var rejectednote = db.SellerNotes.Find(id);

            SellerNote clonenote = new SellerNote();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = 1;
            clonenote.Title          = rejectednote.Title;
            clonenote.Category       = rejectednote.Category;
            clonenote.NoteType       = rejectednote.NoteType;
            clonenote.NumberofPages  = rejectednote.NumberofPages;
            clonenote.Description    = rejectednote.Description;
            clonenote.UniversityName = rejectednote.UniversityName;
            clonenote.Country        = rejectednote.Country;
            clonenote.Course         = rejectednote.Course;
            clonenote.CourseCode     = rejectednote.CourseCode;
            clonenote.Professor      = rejectednote.Professor;
            clonenote.IsPaid         = rejectednote.IsPaid;
            clonenote.SellingPrice   = rejectednote.SellingPrice;
            clonenote.CreatedBy      = user.ID;
            clonenote.CreatedDate    = DateTime.Now;
            clonenote.ModifiedBy     = user.ID;
            clonenote.ModifiedDate   = DateTime.Now;
            clonenote.IsActive       = true;

            db.SellerNotes.Add(clonenote);
            db.SaveChanges();

            clonenote = db.SellerNotes.Find(clonenote.ID);

            if (rejectednote.DisplayPicture != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.DisplayPicture);
                var clonenotefilepath    = "~/Members/" + user.ID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);
                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.DisplayPicture = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                db.SaveChanges();
            }

            if (rejectednote.NotesPreview != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.NotesPreview);
                var clonenotefilepath    = "~/Members/" + user.ID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);

                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.NotesPreview = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                db.SaveChanges();
            }

            var rejectednoteattachement = Server.MapPath("~/Members/" + user.ID + "/" + rejectednote.ID + "/Attachements/");
            var clonenoteattachement    = "~/Members/" + user.ID + "/" + clonenote.ID + "/Attachements/";

            var attachementfilepath = Path.Combine(Server.MapPath(clonenoteattachement));

            Directory.CreateDirectory(attachementfilepath);

            foreach (var files in Directory.GetFiles(rejectednoteattachement))
            {
                FileInfo file = new FileInfo(files);

                if (file.Exists)
                {
                    System.IO.File.Copy(file.ToString(), Path.Combine(attachementfilepath, Path.GetFileName(file.ToString())));
                }

                SellerNotesAttachement attachement = new SellerNotesAttachement();
                attachement.NoteID       = clonenote.ID;
                attachement.FileName     = Path.GetFileName(file.ToString());
                attachement.FilePath     = clonenoteattachement;
                attachement.CreatedDate  = DateTime.Now;
                attachement.CreatedBy    = user.ID;
                attachement.ModifiedDate = DateTime.Now;
                attachement.ModifiedBy   = user.ID;
                attachement.IsActive     = true;

                db.SellerNotesAttachements.Add(attachement);
                db.SaveChanges();
            }


            return(RedirectToAction("Index", "SellNote"));
        }
Example #27
0
        public ActionResult CloneNote(int noteid)
        {
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get rejected note by id
            var rejectednote = _dbcontext.SellerNotes.Find(noteid);

            // create object of sellernote for create clone of note
            SellerNote clonenote = new SellerNote();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = _dbcontext.ReferenceDatas.Where(x => x.Value.ToLower() == "draft").Select(x => x.ID).FirstOrDefault();
            clonenote.Title          = rejectednote.Title;
            clonenote.Category       = rejectednote.Category;
            clonenote.NoteType       = rejectednote.NoteType;
            clonenote.NumberOfPages  = rejectednote.NumberOfPages;
            clonenote.Description    = rejectednote.Description;
            clonenote.UniversityName = rejectednote.UniversityName;
            clonenote.Country        = rejectednote.Country;
            clonenote.Course         = rejectednote.Course;
            clonenote.CourseCode     = rejectednote.CourseCode;
            clonenote.Professor      = rejectednote.Professor;
            clonenote.IsPaid         = rejectednote.IsPaid;
            clonenote.SellingPrice   = rejectednote.SellingPrice;
            clonenote.CreatedBy      = user.UserID;
            clonenote.CreatedDate    = DateTime.Now;
            clonenote.IsActive       = true;

            // save note in database
            _dbcontext.SellerNotes.Add(clonenote);
            _dbcontext.SaveChanges();

            // get clonenote
            clonenote = _dbcontext.SellerNotes.Find(clonenote.ID);

            // if display picture is not null then copy file from rejected note's folder to clone note's new folder
            if (rejectednote.DisplayPicture != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.DisplayPicture);
                var clonenotefilepath    = "~/Members/" + user.UserID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);
                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.DisplayPicture = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                _dbcontext.SaveChanges();
            }

            // if note preview is not null then copy file from rejected note's folder to clone note's new folder
            if (rejectednote.NotesPreview != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.NotesPreview);
                var clonenotefilepath    = "~/Members/" + user.UserID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);

                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.NotesPreview = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                _dbcontext.SaveChanges();
            }

            // attachment path of rejected note and clone note
            var rejectednoteattachement = Server.MapPath("~/Members/" + user.UserID + "/" + rejectednote.ID + "/Attachements/");
            var clonenoteattachement    = "~/Members/" + user.UserID + "/" + clonenote.ID + "/Attachements/";

            var attachementfilepath = Path.Combine(Server.MapPath(clonenoteattachement));

            // create directory for attachement folder
            Directory.CreateDirectory(attachementfilepath);

            // get attachements files from rejected note and copy to clone note
            foreach (var files in Directory.GetFiles(rejectednoteattachement))
            {
                FileInfo file = new FileInfo(files);

                if (file.Exists)
                {
                    System.IO.File.Copy(file.ToString(), Path.Combine(attachementfilepath, Path.GetFileName(file.ToString())));
                }

                // save attachment in database
                SellerNotesAttachment attachement = new SellerNotesAttachment();
                attachement.NoteID      = clonenote.ID;
                attachement.FileName    = Path.GetFileName(file.ToString());
                attachement.FilePath    = clonenoteattachement;
                attachement.CreatedDate = DateTime.Now;
                attachement.CreatedBy   = user.UserID;
                attachement.IsActive    = true;

                _dbcontext.SellerNotesAttachments.Add(attachement);
                _dbcontext.SaveChanges();
            }
            return(RedirectToAction("Dashboard", "SellYourNotes"));
        }
        public ActionResult AddNote(AddNoteModel note, string Command)
        {
            ViewBag.Class = "white-nav";
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (user != null && ModelState.IsValid)
            {
                SellerNote sellernotes = new SellerNote();

                // Save note info in Database
                sellernotes.SellerID       = user.ID;
                sellernotes.Title          = note.Title;
                sellernotes.Status         = Command == "Save" ? 1 : 2;
                sellernotes.Category       = note.Category;
                sellernotes.NoteType       = note.NoteType;
                sellernotes.NumberofPages  = note.NumberofPages;
                sellernotes.Description    = note.Description;
                sellernotes.UniversityName = note.UniversityName;
                sellernotes.Country        = note.Country;
                sellernotes.Course         = note.Course;
                sellernotes.CourseCode     = note.CourseCode;
                sellernotes.Professor      = note.Professor;
                sellernotes.IsPaid         = note.IsPaid;
                sellernotes.SellingPrice   = sellernotes.IsPaid == false ? 0 : note.SellingPrice;
                sellernotes.CreatedDate    = DateTime.Now;
                sellernotes.ModifiedDate   = DateTime.Now;
                sellernotes.CreatedBy      = user.ID;
                sellernotes.ModifiedBy     = user.ID;
                sellernotes.IsActive       = true;

                // If seller add unvalid price
                if (note.IsPaid)
                {
                    if (note.SellingPrice == null || note.SellingPrice < 1)
                    {
                        ModelState.AddModelError("SellingPrice", "Enter valid Selling price");

                        AddNoteModel viewModel = GetDD();

                        return(View(viewModel));
                    }
                }
                if (note.UploadNotes[0] == null)
                {
                    ModelState.AddModelError("UploadNotes", "Enter Note");

                    AddNoteModel viewModel = GetDD();

                    return(View(viewModel));
                }

                db.SellerNotes.Add(sellernotes);
                db.SaveChanges();


                sellernotes = db.SellerNotes.Find(sellernotes.ID);

                //save note picture if User add
                if (note.DisplayPicture != null)
                {
                    string displaypicturefilename = Path.GetFileName(note.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/" + user.ID + "/" + sellernotes.ID + "/"), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    note.DisplayPicture.SaveAs(displaypicturefilepath);
                }
                else
                {
                    var filepath = db.SystemConfigurations.Where(x => x.Name == "DefaultNoteDisplayPicture").FirstOrDefault();

                    sellernotes.DisplayPicture = filepath.Value;
                }


                //save note preview
                if (note.NotesPreview != null)
                {
                    string notespreviewfilename = System.IO.Path.GetFileName(note.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    note.NotesPreview.SaveAs(notespreviewfilepath);
                }

                db.SellerNotes.Attach(sellernotes);
                db.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true;
                db.Entry(sellernotes).Property(x => x.NotesPreview).IsModified   = true;
                db.SaveChanges();

                //save note file
                if (note.UploadNotes[0] != null)
                {
                    foreach (HttpPostedFileBase file in note.UploadNotes)
                    {
                        if (file != null)
                        {
                            string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                            string notesattachementpath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/";
                            CreateDirectoryIfMissing(notesattachementpath);
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);

                            note.NotesPreview.SaveAs(notesattachementfilepath);


                            //save note file into SellerNotesAttachement table
                            SellerNotesAttachement notesattachements = new SellerNotesAttachement
                            {
                                NoteID       = sellernotes.ID,
                                FileName     = notesattachementfilename,
                                FilePath     = notesattachementpath + notesattachementfilename,
                                CreatedDate  = DateTime.Now,
                                CreatedBy    = user.ID,
                                ModifiedDate = DateTime.Now,
                                ModifiedBy   = user.ID,
                                IsActive     = true
                            };

                            db.SellerNotesAttachements.Add(notesattachements);

                            db.SaveChanges();
                        }
                    }
                }
                db.Dispose();

                return(RedirectToAction("Index", "SellNote"));
            }
            else
            {
                AddNoteModel viewModel = GetDD();
                return(View(viewModel));
            }
        }
Example #29
0
        public ActionResult Download(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            NoteCategory           notecategory            = dbobj.NoteCategories.Where(x => x.Id == sellrnote.Category).FirstOrDefault();
            var  Emailid = User.Identity.Name.ToString();
            User user    = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();

            if (sellrnote.IsPaid == false)
            {
                Download download = new Download
                {
                    NoteId     = sellrnote.Id,
                    Seller     = sellrnote.SellerID,
                    downloader = user.ID,
                    isSellerhasAllowedDownloaded = true,
                    AttachmentPath           = objsellernoteattachment.FilePath,
                    IsAttachmentDownloaded   = true,
                    AttachmentDownloadedDate = DateTime.Now,
                    Ispaid         = sellrnote.IsPaid,
                    PurchasedPrice = sellrnote.SellingPrice,
                    NoteTitle      = sellrnote.Title,
                    NoteCategory   = notecategory.name,
                    Createddate    = DateTime.Now,
                    CreatedBy      = user.ID,
                    ModifiedBy     = user.ID,
                    isActive       = true
                };
                dbobj.Downloads.Add(download);
                dbobj.SaveChanges();
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                    MemoryStream output = new MemoryStream();
                    zip.Save(output);
                    return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
                }
            }
            else
            {
                User objuser = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();
                SendEmailtoSeller(objuser.EmailId.ToString());
                Download download = new Download
                {
                    NoteId     = sellrnote.Id,
                    Seller     = sellrnote.SellerID,
                    downloader = user.ID,
                    isSellerhasAllowedDownloaded = false,
                    AttachmentDownloadedDate     = DateTime.Now,
                    Ispaid         = sellrnote.IsPaid,
                    PurchasedPrice = sellrnote.SellingPrice,
                    NoteTitle      = sellrnote.Title,
                    NoteCategory   = notecategory.name,
                    Createddate    = DateTime.Now,
                    CreatedBy      = user.ID,
                    ModifiedBy     = user.ID,
                    isActive       = true
                };
                dbobj.Downloads.Add(download);
                dbobj.SaveChanges();
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }