Esempio n. 1
0
        public ActionResult DeActive(int id)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();


            var Users = db.Users.Where(x => x.IsActive == true && x.ID == id).FirstOrDefault();

            Users.IsActive     = false;
            Users.ModifiedBy   = user.ID;
            Users.ModifiedDate = DateTime.Now;

            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();

            var Notes = db.SellerNotes.Where(x => x.IsActive == true && x.SellerID == Users.ID && x.Status == 4).ToList();

            foreach (var item in Notes)
            {
                item.Status        = 6;
                Users.ModifiedBy   = user.ID;
                Users.ModifiedDate = DateTime.Now;

                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "AdminMembers"));
        }
 public ActionResult AddCountry(ManageCountryViewModel model)
 {
     if (ModelState.IsValid)
     {
         Country countryData = db.Countries.Where(x => x.CountryCode.Equals(model.CountryCode)).FirstOrDefault();
         int     AddedBy     = Convert.ToInt32(Session["ID"]);
         if (countryData != null)
         {
             countryData.Name         = model.CountryName;
             countryData.CountryCode  = model.CountryCode;
             countryData.ModifiedDate = DateTime.Now;
             countryData.ModifiedBy   = AddedBy;
             countryData.IsActive     = true;
             db.SaveChanges();
         }
         else
         {
             Country NewEntry = new Country()
             {
                 Name        = model.CountryName,
                 CountryCode = model.CountryCode,
                 CreatedBy   = AddedBy,
                 CreatedDate = DateTime.Now,
                 IsActive    = true,
             };
             db.Countries.Add(NewEntry);
             db.SaveChanges();
         }
         return(RedirectToAction("ManageCountry", "Country"));
     }
     else
     {
         return(View(model));
     }
 }
Esempio n. 3
0
        public ActionResult Signup(usersignup usersignup)
        {
            bool exist = db.Users.Any(m => m.EmailID == usersignup.emailAddress);

            if (usersignup.password != usersignup.con_password || exist)
            {
                if (usersignup.password != usersignup.con_password)
                {
                    TempData["notMatched"] = "confirm password note matched with password";
                }
                if (exist)
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var user = new User();
                    user.FirstName   = usersignup.firstname;
                    user.LastName    = usersignup.lastname;
                    user.EmailID     = usersignup.emailAddress;
                    user.Password    = usersignup.password;
                    user.RoleID      = 3;
                    user.CreatedDate = DateTime.Now;
                    user.IsActive    = true;
                    db.Users.Add(user);
                    db.SaveChanges();
                    TempData["register"] = "succesfully created";
                    buildEmailTamplate(user.id);
                }
            }
            return(View(usersignup));
        }
 public ActionResult AddType(ManageTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         NoteType countryData = db.NoteTypes.Where(x => x.Name.Equals(model.Type)).FirstOrDefault();
         int      AddedBy     = Convert.ToInt32(Session["ID"]);
         if (countryData != null)
         {
             countryData.Name         = model.Type;
             countryData.Description  = model.Description;
             countryData.ModifiedDate = DateTime.Now;
             countryData.ModifiedBy   = AddedBy;
             countryData.IsActive     = true;
             db.SaveChanges();
         }
         else
         {
             NoteType NewEntry = new NoteType()
             {
                 Name        = model.Type,
                 Description = model.Description,
                 CreatedBy   = AddedBy,
                 CreatedDate = DateTime.Now,
                 IsActive    = true,
             };
             db.NoteTypes.Add(NewEntry);
             db.SaveChanges();
         }
         return(RedirectToAction("ManageType", "Type"));
     }
     else
     {
         return(View(model));
     }
 }
Esempio n. 5
0
        public ActionResult Index(AdminProfileModel admin)
        {
            ViewBag.Profile = "active";

            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            var userProfile = db.UserProfiles.FirstOrDefault(x => x.UserID == user.ID);

            if (ModelState.IsValid)
            {
                user.FirstName = admin.FirstName;
                user.LastName  = admin.LastName;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();

                userProfile.PhoneNumberCountryCode = admin.PhoneCode;
                userProfile.PhoneNumber            = admin.Phone;

                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();

                if (admin.SecondEmail != null)
                {
                    userProfile.SecondaryEmailAddress = admin.SecondEmail;

                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }


                if (admin.ProfilePicture != null)
                {
                    string userprofilename = System.IO.Path.GetFileName(admin.ProfilePicture.FileName);
                    string userprofileext  = System.IO.Path.GetExtension(admin.ProfilePicture.FileName);

                    string storeprofilepath = "~/Members/" + user.ID + "/";

                    CreateDirectoryIfMissing(storeprofilepath);

                    userprofilename = "DP_" + DateTime.Now.ToString("ddMMyyyy") + userprofileext;

                    string userprofilepath = Path.Combine(Server.MapPath(storeprofilepath), userprofilename);
                    userProfile.ProfilePicture = storeprofilepath + userprofilename;

                    admin.ProfilePicture.SaveAs(userprofilepath);
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index", "AdminDashboard"));
            }
            else
            {
                AdminProfileModel admin1 = new AdminProfileModel();
                admin1.CountryList = db.Countries.Where(x => x.IsActive == true).ToList();

                return(View(admin1));
            }
        }
        public ActionResult Approve(int?NoteID)
        {
            SellNote getSellnote = db.SellNotes.Where(x => x.ID == NoteID).FirstOrDefault();

            getSellnote.Status        = Convert.ToInt32(Enums.ReferenceNoteStatus.Approved);
            getSellnote.PublishedDate = DateTime.Now;
            getSellnote.ApprovedBy    = Convert.ToInt32(Session["ID"]);
            db.SaveChanges();
            return(RedirectToAction("NotesUnderReview", "NotesUnderReview"));
        }
Esempio n. 7
0
        public ActionResult InActiveCategory(int id)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            var Category = db.NoteCategories.Where(x => x.ID == id).FirstOrDefault();

            Category.IsActive     = false;
            Category.ModifiedDate = DateTime.Now;
            Category.ModifiedBy   = user.ID;
            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();

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

            var Notes = db.SellerNotes.Where(x => x.IsActive == true && x.ID == id).FirstOrDefault();

            Notes.Status       = 3;
            Notes.ActionedBy   = user.ID;
            Notes.ModifiedBy   = user.ID;
            Notes.ModifiedDate = DateTime.Now;

            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();
            return(RedirectToAction("Index", "AdminNoteUnderReview"));
        }
Esempio n. 9
0
        public ActionResult UnPublishNote(int id)
        {
            //Auth User
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);


            string Remark = Request.Form["Remark"];

            if (String.IsNullOrEmpty(Remark))
            {
                return(Content("Please Enter Remark"));
            }

            var Note = db.SellerNotes.Where(x => x.IsActive == true && x.ID == id).FirstOrDefault();

            var Seller = db.Users.Where(x => x.ID == Note.SellerID).FirstOrDefault();

            Note.ModifiedDate = DateTime.Now;
            Note.ModifiedBy   = user.ID;
            Note.ActionedBy   = user.ID;
            Note.AdminRemarks = Remark;
            Note.Status       = 6;

            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();


            var body = "<p>Hello, {0}</p><br>" +
                       "<p>We want to inform you that, your note {1} has been removed from the portal.</p>" +
                       "<p>Please find our remarks as below -</p>" +
                       "<p>{2}</p><br>" +
                       "<p>Regards</p>" +
                       "<p>Notes MarketPlace</p>";

            var message = new MailMessage();

            message.To.Add(new MailAddress(Seller.Email));                        // Reciever
            message.From       = new MailAddress("*****@*****.**"); // Sender
            message.Subject    = "Sorry! We need to remove your notes from our portal. ";
            message.Body       = string.Format(body, Seller.FirstName + " " + Seller.LastName, Note.Title, Note.AdminRemarks);
            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "******",
                    Password = "******"
                };
                smtp.Credentials = credential;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.EnableSsl   = true;
                smtp.Send(message);
            }
            return(RedirectToAction("Index", "AdminPublishedNote"));
        }
 public ActionResult DeleteReview(int?ID)
 {
     if (ID != null)
     {
         NoteReview noteReview = db.NoteReviews.Where(x => x.ID == (int)ID).FirstOrDefault();
         db.NoteReviews.Remove(noteReview);
         db.SaveChanges();
     }
     return(RedirectToAction("PublishedNotes", "Admin"));
 }
        public ActionResult Index(User user)
        {
            //Auth User
            var isUser = db.Users.Where(a => a.Email == user.Email).FirstOrDefault();


            //If Auth
            if (!db.Users.Any(x => x.Email == user.Email))
            {
                ViewBag.Status = 1;
                return(View(user));
            }

            //Generate 8 character Random Password
            string password = Membership.GeneratePassword(8, 0);

            if (isUser != null)
            {
                //Save Password in Database
                isUser.Password = password;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();
            }

            //Send Mail with Password to User
            var body = "<p>Hello,</p><br>" +
                       "<p>We have generated a new password for you</p>" +
                       "<p>Password : {0}</p><br><br><br><br><br>" +
                       "<p>Regards,</p>" +
                       "<p>Notes Marketplace</p>";

            var message = new MailMessage();

            message.To.Add(new MailAddress(user.Email));                          // Reciever
            message.From       = new MailAddress("*****@*****.**"); // Sender
            message.Subject    = " New Temporary Password has been created for you";
            message.Body       = string.Format(body, password);
            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "******",
                    Password = "******"
                };
                smtp.Credentials = credential;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.EnableSsl   = true;
                smtp.Send(message);

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

            var Spam = db.SellerNotesReportedIssues.Where(x => x.ID == id).FirstOrDefault();

            db.SellerNotesReportedIssues.Remove(Spam);
            db.SaveChanges();

            return(RedirectToAction("Index", "SpamReport"));
        }
Esempio n. 13
0
        public ActionResult AddReview(int id)
        {
            SellerNotesReview sellerNotesReview = new SellerNotesReview();

            //Auth User
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            //Find Note in Download Table
            var download = db.Downloads.Where(x => x.ID == id).FirstOrDefault();

            int    rate    = Convert.ToInt32(Request.Form["rate"]);
            string comment = Request.Form["cmt"];

            if (rate == 0)
            {
                return(Content("Please give Rating"));
            }

            if (string.IsNullOrEmpty(comment))
            {
                return(Content("Please Enter Comment"));
            }

            //Save Info on SellerNoteReview Table
            sellerNotesReview.NoteID             = download.NoteID;
            sellerNotesReview.ReviewedByID       = user.ID;
            sellerNotesReview.AgainstDownloadsID = download.ID;
            sellerNotesReview.Ratings            = rate;
            sellerNotesReview.Comments           = comment;
            sellerNotesReview.CreatedDate        = DateTime.Now;
            sellerNotesReview.CreatedBy          = user.ID;
            sellerNotesReview.ModifiedDate       = DateTime.Now;
            sellerNotesReview.ModifiedBy         = user.ID;
            sellerNotesReview.IsActive           = true;

            db.SellerNotesReviews.Add(sellerNotesReview);
            db.SaveChanges();

            return(RedirectToAction("Index", "MyDownload"));
        }
        public ActionResult PaymentRecieve(int id)
        {
            //Find Entry on Download Table
            Download download = db.Downloads.Find(id);

            //Auth User
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            //in Download Note find Seller and Downloader
            var Downloader = db.Users.Where(x => x.ID == download.Downloader).FirstOrDefault();
            var Seller     = db.Users.Where(x => x.ID == download.Seller).FirstOrDefault();

            SellerNotesAttachement attachement = db.SellerNotesAttachements.Where(x => x.NoteID == download.NoteID).FirstOrDefault();

            //Make Change on Download Table
            db.Downloads.Attach(download);
            download.IsSellerHasAllowedDownload = true;
            download.AttachmentPath             = attachement.FilePath;
            download.AttachmentDownloadedDate   = DateTime.Now;
            download.ModifiedBy   = user.ID;
            download.ModifiedDate = DateTime.Now;
            db.SaveChanges();

            //Send Email to Buyer after Payment Recieve
            var body = "<p>Hello, {0}</p><br>" +
                       "<p>We would like to inform you that, {1} Allows you to download a note. Please login and see My Download tabs to download particular note.</p><br><br>" +
                       "<p>Regards</p>" +
                       "<p>Notes Marketplace</p>";

            var message = new MailMessage();

            message.To.Add(new MailAddress(Downloader.Email));                    // Reciever
            message.From       = new MailAddress("*****@*****.**"); // Sender
            message.Subject    = Seller.FirstName + " " + Seller.LastName + " " + "Allows you to download a note";
            message.Body       = string.Format(body, Downloader.FirstName + " " + Downloader.LastName, Seller.FirstName + " " + Seller.LastName);
            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "******",
                    Password = "******"
                };
                smtp.Credentials = credential;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.EnableSsl   = true;
                smtp.Send(message);
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        public ActionResult Unpublish()
        {
            int      id          = Convert.ToInt32(Request.Form["hiddenId"]);
            SellNote getSellnote = db.SellNotes.Where(x => x.ID == id).FirstOrDefault();

            getSellnote.Status       = Convert.ToInt32(Enums.ReferenceNoteStatus.Removed);
            getSellnote.AdminRemarks = Request.Form["remarks"];
            getSellnote.ModifiedDate = DateTime.Now;
            getSellnote.RejectedBy   = Convert.ToInt32(Session["ID"]);
            getSellnote.ModifiedBy   = Convert.ToInt32(Session["ID"]);
            db.SaveChanges();
            return(RedirectToAction("PublishedNotes", "Admin"));
        }
        public ActionResult Delete(int id)
        {
            //Auth USer
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            //Check Note is Store in Draft Formate
            var note = db.SellerNotes.Where(x => x.ID == id && x.SellerID == user.ID && x.Status == 1).FirstOrDefault();

            if (note == null)
            {
                return(Content("This Note is not Available...."));
            }
            if (note.SellerID != user.ID)
            {
                return(Content("You Can't Delete This Note, This Note doesn't Belong to You"));
            }
            var noteFile = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID).ToList();

            //Delete in Database Table
            foreach (var item in noteFile)
            {
                db.SellerNotesAttachements.Remove(item);
            }

            db.SaveChanges();

            db.SellerNotes.Remove(note);
            db.SaveChanges();

            //Delete in server Folder(Members)
            string PathPreview = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID);

            if (Directory.Exists(PathPreview))
            {
                DeleteDirectory(PathPreview);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Deactivate(int?SellerID)
        {
            User user = db.Users.Where(x => x.ID == (int)SellerID).FirstOrDefault();

            user.IsActive = false;
            List <SellNote> notes = db.SellNotes.Where(x => x.SellerID == SellerID).ToList();

            foreach (var data in notes)
            {
                data.Status = Convert.ToInt32(Enums.ReferenceNoteStatus.Removed);
            }
            db.SaveChanges();
            return(RedirectToAction("Members", "AdminMembers"));
        }
        public ActionResult DeleteReport(int?ID)
        {
            NoteReport report = db.NoteReports.Where(x => x.ID == ID).FirstOrDefault();

            if (ID != null)
            {
                if (report != null)
                {
                    db.NoteReports.Remove(report);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("SpamReport", "Report"));
        }
        public ActionResult EmailConfirm(int regID)
        {
            User user = db.Users.FirstOrDefault(x => x.ID == regID);

            Session["ID"]    = user.ID;
            Session["Email"] = user.Email;
            FormsAuthentication.SetAuthCookie(user.Email, true);
            user.IsEmailVerified = true;
            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();
            db.Dispose();

            if (user.RoleID == 1)
            {
                return(RedirectToAction("Index", "MyProfile"));
            }
            else
            {
                return(RedirectToAction("Index", "AdminDashboard"));
            }
        }
        public ActionResult Index(ChangePasswordModel changePassword)
        {
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            //Enter Password and Db Password Not Match
            if (user.Password != changePassword.OldPassword)
            {
                ModelState.AddModelError("OldPassword", "Enter Valid Old Password");
                return(View(changePassword));
            }

            //New Pass and Confirm Pass not Match
            if (changePassword.NewPassword != changePassword.ConfirmPassword)
            {
                ModelState.AddModelError("confirmpassword", "Password and ConfirmPassword are not Same");
                return(View(changePassword));
            }

            if (user.IsActive == true && ModelState.IsValid)
            {
                user.Password = changePassword.NewPassword;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();

                FormsAuthentication.SignOut();
                Session.Abandon();
                Session.Clear();
                Session.RemoveAll();
                Session["ID"]    = null;
                Session["Email"] = null;
                Session.RemoveAll();

                db.Dispose();
                return(RedirectToAction("Index", "Login"));
            }

            return(View(changePassword));
        }
Esempio n. 21
0
        public ActionResult Index(SystemConfigModel systemConfig)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            ViewBag.Setting = "active";
            ViewBag.MSC     = "active";

            if (ModelState.IsValid)
            {
                SystemConfiguration info = new SystemConfiguration();
                var SupportEmail         = db.SystemConfigurations.Where(x => x.Name == "SupportEmailAddress").FirstOrDefault();
                var ContactNO            = db.SystemConfigurations.Where(x => x.Name == "SupportContactAddress").FirstOrDefault();
                var SecondaryEmail       = db.SystemConfigurations.Where(x => x.Name == "EmailAddresssesForNotify").FirstOrDefault();
                var FacebookUrl          = db.SystemConfigurations.Where(x => x.Name == "FbUrl").FirstOrDefault();
                var TwitterUrl           = db.SystemConfigurations.Where(x => x.Name == "TwitterUrl").FirstOrDefault();
                var LinkedInUrl          = db.SystemConfigurations.Where(x => x.Name == "LinkedInUrl").FirstOrDefault();
                var NoteImage            = db.SystemConfigurations.Where(x => x.Name == "DefaultNoteDisplayPicture").FirstOrDefault();
                var ProfileImage         = db.SystemConfigurations.Where(x => x.Name == "DefaultMemberDisplayPicture").FirstOrDefault();

                if (SupportEmail == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "SupportEmailAddress";
                    info.Value        = systemConfig.Email;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    SupportEmail.Value = systemConfig.Email;
                    info.ModifiedDate  = DateTime.Now;
                    info.ModifiedBy    = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (ContactNO == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "SupportContactAddress";
                    info.Value        = systemConfig.Phone;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    ContactNO.Value   = systemConfig.Phone;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (SecondaryEmail == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "EmailAddresssesForNotify";
                    info.Value        = systemConfig.SecondaryEmail;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    SecondaryEmail.Value = systemConfig.SecondaryEmail;
                    info.ModifiedDate    = DateTime.Now;
                    info.ModifiedBy      = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (FacebookUrl == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "FbUrl";
                    info.Value        = systemConfig.FacebookUrl;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    FacebookUrl.Value = systemConfig.FacebookUrl;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (LinkedInUrl == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "LinkedInUrl";
                    info.Value        = systemConfig.LinkedinUrl;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    LinkedInUrl.Value = systemConfig.LinkedinUrl;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }


                if (TwitterUrl == null)
                {
                    info              = new SystemConfiguration();
                    info.Name         = "TwitterUrl";
                    info.Value        = systemConfig.TwitterUrl;
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    TwitterUrl.Value  = systemConfig.TwitterUrl;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (NoteImage == null)
                {
                    if (systemConfig.ImageNote == null)
                    {
                        ModelState.AddModelError("ImageNote", "Image Note is Required");
                        return(View());
                    }
                    info              = new SystemConfiguration();
                    info.Name         = "DefaultNoteDisplayPicture";
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    if (systemConfig.ImageNote != null)
                    {
                        string ImageNotefilename = Path.GetFileName(systemConfig.ImageNote.FileName);
                        string ImageNotePath     = "~/Members/AdminSystemConfiguration/ImageNote/";
                        CreateDirectoryIfMissing(ImageNotePath);
                        string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/AdminSystemConfiguration/ImageNote/"), ImageNotefilename);
                        info.Value = ImageNotePath + ImageNotefilename;
                        systemConfig.ImageNote.SaveAs(displaypicturefilepath);
                    }
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    if (systemConfig.ImageNote != null)
                    {
                        string   defaultFilename = Directory.GetFiles(Server.MapPath("~/Members/AdminSystemConfiguration/ImageNote/")).FirstOrDefault();
                        string   finalfilename   = System.IO.Path.GetFileName(defaultFilename);
                        string   PathImage       = Request.MapPath("~/Members/AdminSystemConfiguration/ImageNote/" + finalfilename);
                        FileInfo file            = new FileInfo(PathImage);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        string ImageNotefilename      = Path.GetFileName(systemConfig.ImageNote.FileName);
                        string ImageNotePath          = "~/Members/AdminSystemConfiguration/ImageNote/";
                        string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/AdminSystemConfiguration/ImageNote/"), ImageNotefilename);
                        NoteImage.Value = ImageNotePath + ImageNotefilename;
                        systemConfig.ImageNote.SaveAs(displaypicturefilepath);
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();

                        var Note = db.SellerNotes.Where(x => x.DisplayPicture == "~/Members/AdminSystemConfiguration/ImageNote/" + finalfilename).ToList();
                        foreach (var item in Note)
                        {
                            item.DisplayPicture = ImageNotePath + ImageNotefilename;
                            db.Configuration.ValidateOnSaveEnabled = false;
                            db.SaveChanges();
                        }
                    }
                }

                if (ProfileImage == null)
                {
                    if (systemConfig.ImageProfile == null)
                    {
                        ModelState.AddModelError("ImageProfile", "Image Profile is Required");
                        return(View());
                    }
                    info              = new SystemConfiguration();
                    info.Name         = "DefaultMemberDisplayPicture";
                    info.CreatedDate  = DateTime.Now;
                    info.CreatedBy    = user.ID;
                    info.ModifiedDate = DateTime.Now;
                    info.ModifiedBy   = user.ID;
                    info.IsActive     = true;
                    if (systemConfig.ImageProfile != null)
                    {
                        string ImageProfilefilename = Path.GetFileName(systemConfig.ImageProfile.FileName);
                        string ImageProfilePath     = "~/Members/AdminSystemConfiguration/ImageProfile/";
                        CreateDirectoryIfMissing(ImageProfilePath);
                        string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/AdminSystemConfiguration/ImageProfile/"), ImageProfilefilename);
                        info.Value = ImageProfilePath + ImageProfilefilename;
                        systemConfig.ImageProfile.SaveAs(displaypicturefilepath);
                    }
                    db.SystemConfigurations.Add(info);
                    db.SaveChanges();
                }
                else
                {
                    if (systemConfig.ImageProfile != null)
                    {
                        string   defaultFilename = Directory.GetFiles(Server.MapPath("~/Members/AdminSystemConfiguration/ImageProfile/")).FirstOrDefault();
                        string   finalfilename   = System.IO.Path.GetFileName(defaultFilename);
                        string   PathImage       = Request.MapPath("~/Members/AdminSystemConfiguration/ImageProfile/" + finalfilename);
                        FileInfo file            = new FileInfo(PathImage);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        string ImageProfilefilename   = Path.GetFileName(systemConfig.ImageProfile.FileName);
                        string ImageProfilePath       = "~/Members/AdminSystemConfiguration/ImageProfile/";
                        string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/AdminSystemConfiguration/ImageProfile/"), ImageProfilefilename);
                        ProfileImage.Value = ImageProfilePath + ImageProfilefilename;
                        systemConfig.ImageProfile.SaveAs(displaypicturefilepath);
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();

                        var User = db.UserProfiles.Where(x => x.ProfilePicture == "~/Members/AdminSystemConfiguration/ImageProfile/" + finalfilename).ToList();
                        foreach (var item in User)
                        {
                            item.ProfilePicture = ImageProfilePath + ImageProfilefilename;
                            db.Configuration.ValidateOnSaveEnabled = false;
                            db.SaveChanges();
                        }
                    }
                }

                ViewBag.sucess = "Record Updated Sucessfully";
                return(View());
            }


            return(View());
        }
        public ActionResult UserProfile(UserProfileViewModel user)
        {
            user.genderList  = db.genders.ToList();
            user.countryList = db.Countries.Where(m => m.IsActive == true).ToList();
            if (ModelState.IsValid)
            {
                User usrname = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault();

                var userprofile = db.UserProfiles.Where(m => m.UserID == usrname.id).SingleOrDefault();
                if (userprofile != null)
                {
                    usrname.FirstName = user.FirstName;
                    usrname.LastName  = user.LastName;
                    db.Users.Attach(usrname);
                    db.Entry(usrname).Property(m => m.FirstName).IsModified = true;
                    db.Entry(usrname).Property(m => m.LastName).IsModified  = true;
                    db.SaveChanges();
                    userprofile.AddressLine1     = user.Address1;
                    userprofile.AddressLine2     = user.Address2;
                    userprofile.City             = user.city;
                    userprofile.College          = user.college;
                    userprofile.Country          = user.usrCountry;
                    userprofile.ModifiedDate     = DateTime.Now;
                    userprofile.ModifiedBy       = usrname.id;
                    userprofile.DOB              = user.BirthDate;
                    userprofile.Gender           = user.gender;
                    userprofile.PhoneNumber      = user.PhonNumber;
                    userprofile.PhoneNumber_code = user.countryCode;
                    if (user.profilepicture != null)
                    {
                        string filename = System.IO.Path.GetFileName(user.profilepicture.FileName);
                        filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-" + filename;
                        string FilePath = "~/Membere/" + usrname.id + "/";
                        bool   exist    = Directory.Exists(Server.MapPath(FilePath));
                        if (!exist)
                        {
                            Directory.CreateDirectory(Server.MapPath(FilePath));
                        }
                        userprofile.ProfilePicture = FilePath + filename;
                        user.profilepicPath        = Path.Combine(Server.MapPath(FilePath), (filename));
                        user.profilepicture.SaveAs(user.profilepicPath);
                    }
                    else
                    {
                        userprofile.ProfilePicture = user.profilepicPath;
                    }
                    userprofile.State      = user.state;
                    userprofile.University = user.University;
                    userprofile.ZipCode    = user.zipCode;
                    db.UserProfiles.Attach(userprofile);
                    db.Entry(userprofile).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Serch_note", "Home"));
                }
                else
                {
                    usrname.FirstName = user.FirstName;
                    usrname.LastName  = user.LastName;
                    db.Users.Attach(usrname);
                    db.Entry(usrname).Property(m => m.FirstName).IsModified = true;
                    db.Entry(usrname).Property(m => m.LastName).IsModified  = true;
                    db.SaveChanges();
                    UserProfile profile = new UserProfile();
                    profile.UserID = usrname.id;
                    profile.DOB    = user.BirthDate;
                    profile.Gender = user.gender;
                    if ((user.PhonNumber == null && user.countryCode == null) || (user.PhonNumber != null && user.countryCode != null))
                    {
                        profile.PhoneNumber_code = user.countryCode;
                        profile.PhoneNumber      = user.PhonNumber;
                    }

                    if (user.profilepicture != null)
                    {
                        string filename = System.IO.Path.GetFileName(user.profilepicture.FileName);
                        filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-" + filename;
                        string FilePath = "~/Membere/" + usrname.id + "/";
                        bool   exist    = Directory.Exists(Server.MapPath(FilePath));
                        if (!exist)
                        {
                            Directory.CreateDirectory(Server.MapPath(FilePath));
                        }
                        profile.ProfilePicture = FilePath + filename;
                        user.profilepicPath    = Path.Combine(Server.MapPath(FilePath), (filename));
                        user.profilepicture.SaveAs(user.profilepicPath);
                    }


                    profile.AddressLine1 = user.Address1;
                    profile.AddressLine2 = user.Address2;
                    profile.City         = user.city;
                    profile.State        = user.state;
                    profile.ZipCode      = user.zipCode;
                    profile.Country      = user.usrCountry;
                    profile.University   = user.University;
                    profile.College      = user.college;
                    profile.CreatedDate  = DateTime.Now;
                    profile.CreatedBy    = usrname.id;
                    db.UserProfiles.Add(profile);
                    db.SaveChanges();
                    return(RedirectToAction("Serch_note", "Home"));
                }
            }
            return(View(user));
        }
        public ActionResult ManageSystemConfiguration(SystemConfigurationViewModel model,
                                                      HttpPostedFileBase DefaultProfilePicturefile,
                                                      HttpPostedFileBase DefaultNotePicturefile)
        {
            if (ModelState.IsValid)
            {
                string DefaultProfilePictureFileName;
                string DefaultNotePictureFileName;
                SystemConfiguration supportEmail = db.SystemConfigurations.Where(x => x.Keys.Equals("SupportEmail")).FirstOrDefault();
                supportEmail.Value       = model.SupportEmail;
                supportEmail.CreatedDate = DateTime.Now;
                supportEmail.CreatedBy   = Convert.ToInt32(Session["ID"]);
                SystemConfiguration SupportPhoneNumber = db.SystemConfigurations.Where(x => x.Keys.Equals("SupportPhoneNumber")).FirstOrDefault();
                SupportPhoneNumber.Value       = model.SupportContactNumber;
                SupportPhoneNumber.CreatedDate = DateTime.Now;
                SupportPhoneNumber.CreatedBy   = Convert.ToInt32(Session["ID"]);
                if (model.Facebook != null)
                {
                    SystemConfiguration Facebook = db.SystemConfigurations.Where(x => x.Keys.Equals("Facebook")).FirstOrDefault();
                    Facebook.Value       = model.Facebook;
                    Facebook.CreatedDate = DateTime.Now;
                    Facebook.CreatedBy   = Convert.ToInt32(Session["ID"]);
                }
                if (model.Twitter != null)
                {
                    SystemConfiguration Twitter = db.SystemConfigurations.Where(x => x.Keys.Equals("Twitter")).FirstOrDefault();
                    Twitter.Value       = model.Twitter;
                    Twitter.CreatedDate = DateTime.Now;
                    Twitter.CreatedBy   = Convert.ToInt32(Session["ID"]);
                }
                if (model.Linkdin != null)
                {
                    SystemConfiguration Linkedin = db.SystemConfigurations.Where(x => x.Keys.Equals("Linkedin")).FirstOrDefault();
                    Linkedin.Value       = model.Linkdin;
                    Linkedin.CreatedDate = DateTime.Now;
                    Linkedin.CreatedBy   = Convert.ToInt32(Session["ID"]);
                }
                SystemConfiguration DefaultNotePicture = db.SystemConfigurations.Where(x => x.Keys.Equals("DefaultNotePicture")).FirstOrDefault();
                if (DefaultNotePicturefile != null)
                {
                    var fileExtension = Path.GetExtension(DefaultNotePicturefile.FileName);
                    DefaultNotePictureFileName = "DefaultNotePicture" + fileExtension;

                    var File = CheckifPathExistForCurrentUser() + DefaultNotePicture.Value;

                    if (System.IO.File.Exists(File))
                    {
                        System.IO.File.Delete(File);
                    }

                    DefaultNotePicture.Value       = DefaultNotePictureFileName;
                    DefaultNotePicture.CreatedDate = DateTime.Now;
                    DefaultNotePicture.CreatedBy   = Convert.ToInt32(Session["ID"]);
                    DefaultNotePictureFileName     = CheckifPathExistForCurrentUser() + DefaultNotePictureFileName;

                    DefaultNotePicturefile.SaveAs(DefaultNotePictureFileName);
                    db.SaveChanges();
                }
                SystemConfiguration DefaultProfilePicture = db.SystemConfigurations.Where(x => x.Keys.Equals("DefaultProfilePicture")).FirstOrDefault();
                if (DefaultProfilePicturefile != null)
                {
                    var fileExtension = Path.GetExtension(DefaultProfilePicturefile.FileName);
                    DefaultProfilePictureFileName = "DefaultProfilePicture" + fileExtension;

                    var File = CheckifPathExistForCurrentUser() + DefaultProfilePicture.Value;

                    if (System.IO.File.Exists(File))
                    {
                        System.IO.File.Delete(File);
                    }

                    DefaultProfilePicture.Value       = DefaultProfilePictureFileName;
                    DefaultProfilePicture.CreatedDate = DateTime.Now;
                    DefaultProfilePicture.CreatedBy   = Convert.ToInt32(Session["ID"]);
                    DefaultProfilePictureFileName     = CheckifPathExistForCurrentUser() + DefaultProfilePictureFileName;

                    DefaultProfilePicturefile.SaveAs(DefaultProfilePictureFileName);
                    db.SaveChanges();
                }

                return(RedirectToAction("ManageSystemConfiguration", "SystemConfiguration"));
            }
            else
            {
                return(View(model));
            }
        }
Esempio n. 24
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"));
        }
Esempio n. 25
0
 public ActionResult AddAdministrator(ManageAdministratorViewModel model)
 {
     if (ModelState.IsValid)
     {
         int  AddedBy = Convert.ToInt32(Session["ID"]);
         User user    = db.Users.Where(x => x.EmailID.Equals(model.Email)).FirstOrDefault();
         if (user != null)
         {
             UserProfile userProfile = db.UserProfiles.Where(x => x.UserID == user.ID).FirstOrDefault();
             user.FirstName    = model.FirstName;
             user.LastName     = model.LastName;
             user.ModifiedBy   = AddedBy;
             user.ModifiedDate = DateTime.Now;
             user.IsActive     = true;
             if (userProfile != null)
             {
                 userProfile.CountryCode  = model.CountryCode;
                 userProfile.PhoneNumber  = model.PhoneNumber;
                 userProfile.ModifiedDate = DateTime.Now;
                 userProfile.ModifiedBy   = AddedBy;
                 db.SaveChanges();
             }
             else
             {
                 UserProfile NewEntry = new UserProfile()
                 {
                     UserID       = user.ID,
                     PhoneNumber  = model.PhoneNumber,
                     AddressLine1 = "Admin",
                     AddressLine2 = "Admin",
                     City         = "Admin",
                     State        = "Admin",
                     ZipCode      = "Admin",
                     Country      = "Admin",
                     CountryCode  = model.CountryCode,
                     CreatedDate  = DateTime.Now,
                     CreatedBy    = AddedBy,
                 };
                 db.UserProfiles.Add(NewEntry);
                 db.SaveChanges();
             }
             db.SaveChanges();
         }
         else
         {
             int  Admin    = Convert.ToInt32(Enums.UserRoleId.Admin);
             User NewEntry = new User()
             {
                 FirstName       = model.FirstName,
                 LastName        = model.LastName,
                 EmailID         = model.Email,
                 RoleID          = Admin,
                 CreatedBy       = AddedBy,
                 CreatedDate     = DateTime.Now,
                 IsEmailVerified = true,
                 Password        = "******",
                 IsActive        = true,
             };
             db.Users.Add(NewEntry);
             db.SaveChanges();
             UserProfile NewProfile = new UserProfile()
             {
                 UserID       = NewEntry.ID,
                 PhoneNumber  = model.PhoneNumber,
                 CountryCode  = model.CountryCode,
                 AddressLine1 = "Admin",
                 AddressLine2 = "Admin",
                 City         = "Admin",
                 State        = "Admin",
                 ZipCode      = "Admin",
                 Country      = "Admin",
                 CreatedDate  = DateTime.Now,
                 CreatedBy    = AddedBy,
             };
             db.UserProfiles.Add(NewProfile);
             db.SaveChanges();
         }
         return(RedirectToAction("ManageAdministrator", "Administrator"));
     }
     else
     {
         return(View(model));
     }
 }
        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"));
        }
        public ActionResult Index(MyProfileModel profile)
        {
            //Auth User
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            //Check if user already Enter Profile Detail or Not
            var CheckUserProfile = db.UserProfiles.Where(x => x.UserID == user.ID).FirstOrDefault();

            if (user != null && ModelState.IsValid)
            {
                //if User Came on this Page First Time and want To Update Profile Info
                if (CheckUserProfile == null)
                {
                    UserProfile userProfile = new UserProfile();

                    user.FirstName    = profile.FirstName;
                    user.LastName     = profile.LastName;
                    user.ModifiedDate = DateTime.Now;
                    user.ModifiedBy   = user.ID;

                    db.Configuration.ValidateOnSaveEnabled = false;


                    userProfile.UserID = user.ID;
                    userProfile.DOB    = profile.DOB;
                    userProfile.Gender = profile.Gender;
                    userProfile.PhoneNumberCountryCode = profile.CountryPhoneCode;
                    userProfile.PhoneNumber            = profile.PhoneNumber;
                    userProfile.AddressLine1           = profile.AddressOne;
                    userProfile.AddressLine2           = profile.AddressTwo;
                    userProfile.City         = profile.City;
                    userProfile.State        = profile.State;
                    userProfile.ZipCode      = profile.ZipCode;
                    userProfile.Country      = profile.Country;
                    userProfile.University   = profile.University;
                    userProfile.College      = profile.College;
                    userProfile.CreatedDate  = DateTime.Now;
                    userProfile.CreatedBy    = user.ID;
                    userProfile.ModifiedDate = DateTime.Now;
                    userProfile.ModifiedBy   = user.ID;

                    if (profile.ProfilePicture != null)
                    {
                        string userprofilename = System.IO.Path.GetFileName(profile.ProfilePicture.FileName);
                        string userprofileext  = System.IO.Path.GetExtension(profile.ProfilePicture.FileName);

                        string storeprofilepath = "~/Members/" + user.ID + "/";

                        userprofilename = "DP_" + DateTime.Now.ToString("ddMMyyyy") + userprofileext;

                        CreateDirectoryIfMissing(storeprofilepath);

                        string userprofilepath = Path.Combine(Server.MapPath(storeprofilepath), userprofilename);
                        userProfile.ProfilePicture = storeprofilepath + userprofilename;

                        profile.ProfilePicture.SaveAs(userprofilepath);
                    }
                    else
                    {
                        var filepath = db.SystemConfigurations.Where(x => x.Name == "DefaultMemberDisplayPicture").FirstOrDefault();
                        userProfile.ProfilePicture = filepath.Value;
                    }

                    db.UserProfiles.Add(userProfile);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "SearchNote"));
                }
                //if User Came on this Page Second Time and want To Update Profile Info
                else
                {
                    user.FirstName    = profile.FirstName;
                    user.LastName     = profile.LastName;
                    user.ModifiedDate = DateTime.Now;
                    user.ModifiedBy   = user.ID;

                    db.Configuration.ValidateOnSaveEnabled = false;

                    UserProfile ExistUser = db.UserProfiles.FirstOrDefault(x => x.UserID == user.ID);

                    ExistUser.DOB    = profile.DOB;
                    ExistUser.Gender = profile.Gender;
                    ExistUser.PhoneNumberCountryCode = profile.CountryPhoneCode;
                    ExistUser.PhoneNumber            = profile.PhoneNumber;
                    ExistUser.AddressLine1           = profile.AddressOne;
                    ExistUser.AddressLine2           = profile.AddressTwo;
                    ExistUser.City         = profile.City;
                    ExistUser.State        = profile.State;
                    ExistUser.ZipCode      = profile.ZipCode;
                    ExistUser.Country      = profile.Country;
                    ExistUser.University   = profile.University;
                    ExistUser.College      = profile.College;
                    ExistUser.ModifiedDate = DateTime.Now;
                    ExistUser.ModifiedBy   = user.ID;

                    if (profile.ProfilePicture != null)
                    {
                        string   PathImage = "~/Members/" + user.ID + "/" + Path.GetFileName(ExistUser.ProfilePicture);
                        FileInfo file      = new FileInfo(PathImage);
                        if (file.Exists)
                        {
                            file.Delete();
                        }

                        string userprofilename = System.IO.Path.GetFileName(profile.ProfilePicture.FileName);
                        string userprofileext  = System.IO.Path.GetExtension(profile.ProfilePicture.FileName);

                        string storeprofilepath = "~/Members/" + user.ID + "/";

                        userprofilename = "DP_" + DateTime.Now.ToString("ddMMyyyy") + userprofileext;

                        string userprofilepath = Path.Combine(Server.MapPath(storeprofilepath), userprofilename);
                        ExistUser.ProfilePicture = storeprofilepath + userprofilename;

                        profile.ProfilePicture.SaveAs(userprofilepath);
                    }
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "SearchNote"));
                }
            }
            var countryList = db.Countries.Where(x => x.IsActive == true).ToList();
            var genderList  = db.ReferenceDatas.Where(x => x.IsActive == true && x.RefCategory == "Gender").ToList();

            MyProfileModel myProfileModel = new MyProfileModel();

            myProfileModel.CountryList = countryList;
            myProfileModel.GenderList  = genderList;

            myProfileModel.FirstName = user.FirstName;
            myProfileModel.LastName  = user.LastName;
            myProfileModel.Email     = user.Email;

            return(View(myProfileModel));
        }
        public ActionResult DownloadNote(int noteId)
        {
            //Auth User as Buyer
            var buyer = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            //If Buyer Didnot Enter UserProfile the Redirect First on MyProfile Page
            var Profile = db.UserProfiles.Where(x => x.UserID == buyer.ID).FirstOrDefault();

            if (Profile == null)
            {
                return(RedirectToAction("Index", "MyProfile"));
            }


            //Note which User want to download
            var note = db.SellerNotes.Find(noteId);
            //Note File Attachment
            var fileAttachNote = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID).ToList();
            //Note Seller Info
            var seller = db.Users.Where(x => x.ID == note.SellerID).FirstOrDefault();


            if (buyer.RoleID != 1)
            {
                string        Apath = Server.MapPath("~/Members/" + seller.ID + "/" + note.ID + "/Attachements/");
                DirectoryInfo Adir  = new DirectoryInfo(Apath);
                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in Adir.GetFiles())
                        {
                            string filepath = Apath + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }


            //if User download First Time free Note
            var firstTime = db.Downloads.Where(x => x.NoteID == note.ID && x.Seller == seller.ID && x.Downloader == buyer.ID && x.IsSellerHasAllowedDownload == true).FirstOrDefault();


            //if Note is Paid then Store Info in Download Table
            Download download = new Download
            {
                NoteID     = note.ID,
                Seller     = note.SellerID,
                Downloader = buyer.ID,
                IsSellerHasAllowedDownload = note.IsPaid ? false : true,
                AttachmentPath             = note.IsPaid ? null : fileAttachNote[0].FilePath,
                IsAttachmentDownloaded     = note.IsPaid ? false : true,
                AttachmentDownloadedDate   = note.IsPaid ? (DateTime?)null : DateTime.Now,
                IsPaid         = note.IsPaid,
                PurchasedPrice = note.SellingPrice,
                NoteTitle      = note.Title,
                NoteCategory   = note.NoteCategory.Name,
                CreatedDate    = DateTime.Now,
                CreatedBy      = buyer.ID,
                ModifiedDate   = DateTime.Now,
                ModifiedBy     = buyer.ID
            };


            //Downlaod Note if User Note is Free and User Is not First Time Downlaod
            if (firstTime != null && firstTime.IsSellerHasAllowedDownload == true)
            {
                firstTime.ModifiedDate = DateTime.Now;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();

                string        fpath = Server.MapPath("~/Members/" + seller.ID + "/" + note.ID + "/Attachements/");
                DirectoryInfo fdir  = new DirectoryInfo(fpath);
                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in fdir.GetFiles())
                        {
                            string filepath = fpath + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }
            db.Downloads.Add(download);
            db.SaveChanges();


            //If Note is Paid then Send Mail To Seller
            if (note.IsPaid)
            {
                var body = "<p>Hello, {0}</p><br>" +
                           "<p>We would like to inform you that, {1} wants to purchase your notes. Please see Buyer Requests tab and allow download access to Buyer if you have received the payment from him.</p><br><br><br>" +
                           "<p>Regards,</p>" +
                           "<p>NoteMarketPlace</p>";

                var message = new MailMessage();
                message.To.Add(new MailAddress(seller.Email));                        // Reciever
                message.From       = new MailAddress("*****@*****.**"); // Sender
                message.Subject    = buyer.FirstName + " " + buyer.LastName + " wants to purchase your notes";
                message.Body       = string.Format(body, seller.FirstName + " " + seller.LastName, buyer.FirstName + " " + buyer.LastName);
                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    smtp.Send(message);
                }
                TempData["Requested"] = "Requested";
                return(RedirectToAction("NoteDetail", "SearchNote", new { id = noteId }));
            }

            //Download Note iF its Free and FirstTime Downlaod Note
            string        path = Server.MapPath("~/Members/" + seller.ID + "/" + note.ID + "/Attachements/");
            DirectoryInfo dir  = new DirectoryInfo(path);

            using (var memoryStream = new MemoryStream())
            {
                using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (var item in dir.GetFiles())
                    {
                        string filepath = path + item.ToString();
                        ziparchive.CreateEntryFromFile(filepath, item.ToString());
                    }
                }
                return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
            }
        }
        public ActionResult Index([Bind(Include = "FirstName,LastName,Email,Password,ConfirmPassword")] User user)
        {
            if (ModelState.IsValid)
            {
                Match isPassword  = Regex.Match(user.Password, @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,24}", RegexOptions.IgnorePatternWhitespace);
                Match isFirstName = Regex.Match(user.FirstName, @"^[a-zA-Z]+$", RegexOptions.IgnorePatternWhitespace);
                Match isLastName  = Regex.Match(user.LastName, @"^[a-zA-Z]+$", RegexOptions.IgnorePatternWhitespace);

                //Email already Exist
                if (db.Users.Any(x => x.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "This Email Already Exist");
                    return(View(user));
                }

                //Password and ConfirmPassword doesn't Match
                if (!(user.Password.Equals(user.ConfirmPassword)))
                {
                    ModelState.AddModelError("ConfirmPassword", "Password and ConfirmPassword are not Same");
                    return(View(user));
                }

                //Password is not Valid
                if (!isPassword.Success)
                {
                    ModelState.AddModelError("Password", "Password shold contain 6 long, 1 - special, digit, upper, lower char");
                    return(View(user));
                }

                //FirstName And LastName is Not valid
                if (!isFirstName.Success)
                {
                    ModelState.AddModelError("FirstName", "Use Only Alphabet");
                    return(View(user));
                }
                if (!isLastName.Success)
                {
                    ModelState.AddModelError("LastName", "Use Only Alphabet");
                    return(View(user));
                }

                user.RoleID          = 1;
                user.IsActive        = true;
                user.CreatedDate     = DateTime.Now;
                user.IsEmailVerified = false;
                db.Users.Add(user);
                db.SaveChanges();

                //Build Email Template
                BuildEmailVerifyTemplate(user.ID);

                //Save Cookie
                Session["ID"]    = user.ID;
                Session["Email"] = user.Email;

                ViewBag.Status = 1;

                ModelState.Clear();

                db.Dispose();
                return(View());
            }
            else
            {
                //If Fail to Signup
                ViewBag.Status = 1;
                ViewBag.Class  = "danger";
                ViewBag.Msg    = "Fail to Signup";
                return(View(user));
            }
        }
Esempio n. 30
0
        public ActionResult ForgotPassword(User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    LoginEntity userExist = new LoginEntity();
                    bool        IsExist   = userExist.EmailExistOrNot(user.EmailID);

                    if (IsExist == true)
                    {
                        //password Generator
                        string numbers        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()-=";
                        Random objrandom      = new Random();
                        string passwordString = "";
                        string strrandom      = string.Empty;
                        for (int i = 0; i < 15; i++)
                        {
                            int temp = objrandom.Next(0, numbers.Length);
                            passwordString = numbers.ToCharArray()[temp].ToString();
                            strrandom     += passwordString;
                        }

                        //update password in database
                        var PasswordOfUser = db.Users.Where(x => x.EmailID.Equals(user.EmailID)).FirstOrDefault();
                        PasswordOfUser.Password = strrandom;
                        db.SaveChanges();

                        // Email sending
                        var sender   = new MailAddress(ConstantStrings.supportEmail, ConstantStrings.supportName);
                        var receiver = new MailAddress(user.EmailID, user.FirstName);
                        var password = ConstantStrings.supportPassword;
                        var body     = string.Empty;
                        var subject  = "New Temporary Password has been created for you";

                        using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplates/ForgotPasswordMail.html")))
                        {
                            body = reader.ReadToEnd();
                        }
                        body = body.Replace("{newPassword}", strrandom);


                        var smtp = new SmtpClient
                        {
                            Host                  = System.Configuration.ConfigurationManager.AppSettings["Host"].ToString(),
                            Port                  = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]),
                            EnableSsl             = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["EnableSsl"]),
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = Convert.ToBoolean(System.Configuration.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);
                        }

                        ModelState.AddModelError("EmailID", "Please Check your Email ID for Updated Password");
                        return(View(user));
                    }
                    else
                    {
                        ModelState.AddModelError("EmailID", "Please Enter Valid Email ID");
                        return(View(user));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Login", "Account"));
        }