Beispiel #1
0
        public ActionResult MakeNoteInReview(int id)
        {
            // get note by id
            var note = context.SellerNotes.Where(x => x.ID == id).FirstOrDefault();

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

            // get logged in user
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // notes status id for in review
            var inreviewid = context.ReferenceData.Where(x => x.Value.ToLower() == "in review").Select(x => x.ID).FirstOrDefault();

            // update status
            note.Status       = inreviewid;
            note.ModifiedDate = DateTime.Now;
            note.ModifiedBy   = user.ID;

            // save note in database
            context.Entry(note).State = EntityState.Modified;
            context.SaveChanges();

            return(RedirectToAction("NotesUnderReview"));
        }
        public ActionResult UnPublishNote(FormCollection form)
        {
            int    noteid = Convert.ToInt32(form["noteid"]);
            string remark = form["unpublish-remark"];

            // get user
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
            // get note
            var note = context.SellerNotes.Where(x => x.ID == noteid).FirstOrDefault();

            // get note status removed id
            int removedid = context.ReferenceData.Where(x => x.Value.ToLower() == "removed").Select(x => x.ID).FirstOrDefault();

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

            // update note status
            note.Status       = removedid;
            note.ModifiedBy   = user.ID;
            note.ModifiedDate = DateTime.Now;

            // save note in database
            context.Entry(note).State = EntityState.Modified;
            context.SaveChanges();

            // get seller user objecct
            var seller = context.Users.Where(x => x.ID == note.SellerID).FirstOrDefault();

            // send mail to seller
            UnpublishNoteTemplate(remark, seller, note);

            return(RedirectToAction("Dashboard", "Admin"));
        }
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            var   take_email = User.Identity.Name.ToString();
            Users obj        = context.Users.Where(x => x.EmailID == take_email).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (string.Compare(model.OldPassword, obj.Password) == 0)
                {
                    obj.Password     = model.NewPassword;
                    obj.ModifiedDate = DateTime.Now;

                    context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();

                    FormsAuthentication.SignOut();
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ModelState.AddModelError("OldPassword", "Your OldPassword Is Incorrect");
                }
            }
            return(View());
        }
Beispiel #4
0
        public ActionResult DeactiveMember(int memberid)
        {
            // get logged in admin
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).First();

            // get ids of note status removed and published
            var removedid   = context.ReferenceData.Where(x => x.Value.ToLower() == "removed").Select(x => x.ID).FirstOrDefault();
            var publishedid = context.ReferenceData.Where(x => x.Value.ToLower() == "published").Select(x => x.ID).FirstOrDefault();

            // get member by member id
            var member = context.Users.Where(x => x.ID == memberid && x.IsActive == true).First();

            // make member inactive
            member.IsActive     = false;
            member.ModifiedDate = DateTime.Now;
            member.ModifiedBy   = user.ID;

            // save updated member record
            context.Entry(member).State = EntityState.Modified;
            context.SaveChanges();

            // get member's published notes list
            var notelist = context.SellerNotes.Where(x => x.SellerID == member.ID && x.Status == publishedid && x.IsActive == true).ToList();

            // make member's each published note status removed
            foreach (var note in notelist)
            {
                note.Status       = removedid;
                note.ModifiedDate = DateTime.Now;
                note.ModifiedBy   = user.ID;

                context.Entry(note).State = EntityState.Modified;
                context.SaveChanges();
            }

            return(RedirectToAction("Members", "AdminMembers"));
        }
        public ActionResult DownloadNotes(int noteid)
        {
            // get note from SellerNotes table
            var note = context.SellerNotes.Find(noteid);

            // if note is not found
            if (note == null)
            {
                return(HttpNotFound());
            }
            // get first object of seller note attachement for attachement
            var noteattachement = context.SellerNotesAttachements.Where(x => x.NoteID == note.ID).FirstOrDefault();
            // get logged in user
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // variable for attachement path
            string path;

            // note's seller if and logged in user's id is same it means user want to download his own book
            // then we need to provide downloaded note without entry in download tables
            if (note.SellerID == user.ID)
            {
                // get attavhement path
                path = Server.MapPath(noteattachement.FilePath);

                DirectoryInfo dir = new DirectoryInfo(path);
                // create zip of attachement
                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in dir.GetFiles())
                        {
                            // file path is attachement path + file name
                            string filepath = path + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    // return zip
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }

            // if note is free then we need to add entry in download table with allow download is true
            // downloaded date time is current date time for first time download
            // if user download again then we have to return zip of attachement without changes in data
            if (note.IsPaid == false)
            {
                // if user has already downloaded note then get download object
                var downloadfreenote = context.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == true && x.AttachmentPath != null).FirstOrDefault();
                // if user is not downloaded
                if (downloadfreenote == null)
                {
                    // create download object
                    Downloads download = new Downloads
                    {
                        NoteID     = note.ID,
                        Seller     = note.SellerID,
                        Downloader = user.ID,
                        IsSellerHasAllowedDownload = true,
                        AttachmentPath             = noteattachement.FilePath,
                        IsAttachmentDownloaded     = true,
                        AttachmentDownloadedDate   = DateTime.Now,
                        IsPaid         = note.IsPaid,
                        PurchasedPrice = note.SellingPrice,
                        NoteTitle      = note.Title,
                        NoteCategory   = note.NoteCategories.Name,
                        CreatedDate    = DateTime.Now,
                        CreatedBy      = user.ID,
                    };

                    // save download object in database
                    context.Downloads.Add(download);
                    context.SaveChanges();

                    path = Server.MapPath(download.AttachmentPath);
                }
                // if user is already downloaded note then get attachement path
                else
                {
                    path = Server.MapPath(downloadfreenote.AttachmentPath);
                }

                DirectoryInfo dir = new DirectoryInfo(path);
                // create zip of attachement
                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in dir.GetFiles())
                        {
                            // file path is attachement path + file name
                            string filepath = path + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    // return zip
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }
            // if note is paid
            else
            {
                // get download object
                var downloadpaidnote = context.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == true && x.AttachmentPath != null).FirstOrDefault();

                // if user is not already downloaded
                if (downloadpaidnote != null)
                {
                    // if user is download note first time then we need to update following record in download table
                    if (downloadpaidnote.IsAttachmentDownloaded == false)
                    {
                        downloadpaidnote.AttachmentDownloadedDate = DateTime.Now;
                        downloadpaidnote.IsAttachmentDownloaded   = true;
                        downloadpaidnote.ModifiedDate             = DateTime.Now;
                        downloadpaidnote.ModifiedBy = user.ID;

                        // update ans save data in database
                        context.Entry(downloadpaidnote).State = EntityState.Modified;
                        context.SaveChanges();
                    }

                    // get attachement path
                    path = Server.MapPath(downloadpaidnote.AttachmentPath);

                    DirectoryInfo dir = new DirectoryInfo(path);

                    // create zip of attachement
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                        {
                            foreach (var item in dir.GetFiles())
                            {
                                // file path is attachement path + file name
                                string filepath = path + item.ToString();
                                ziparchive.CreateEntryFromFile(filepath, item.ToString());
                            }
                        }
                        // return zip
                        return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                    }
                }
                return(RedirectToAction("Notes", "NotesDetails", new { id = noteid }));
            }
        }
        public ActionResult UserProfile(UserProfileModel userprofileviewmodel)
        {
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // check if ModelState is valid or not
            if (ModelState.IsValid)
            {
                // check if profile picture is not null
                if (userprofileviewmodel.ProfilePicture != null)
                {
                    // get image size and check that it is not more than 10 MB
                    var profilepicsize = userprofileviewmodel.ProfilePicture.ContentLength;
                    if (profilepicsize > 10 * 1024 * 1024)
                    {
                        // if image size is more than 10 MB show error
                        ModelState.AddModelError("ProfilePicture", "Image size limit is 10 MB");
                        userprofileviewmodel.CountryList = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                        userprofileviewmodel.GenderList  = _dbcontext.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                        return(View(userprofileviewmodel));
                    }
                }



                // get logged in user's profile if exists
                var profile = _dbcontext.UserProfile.Where(x => x.User_ID == user.ID).FirstOrDefault();

                // if profile is not null then edit userprofile
                if (profile != null)

                {
                    profile.DOB    = userprofileviewmodel.DOB;
                    profile.Gender = userprofileviewmodel.Gender;
                    profile.Phone_number_Country_Code = userprofileviewmodel.PhoneNumberCountryCode;
                    profile.Phone_number   = userprofileviewmodel.PhoneNumber;
                    profile.Address_Line_1 = userprofileviewmodel.AddressLine1;
                    if (!String.IsNullOrEmpty(userprofileviewmodel.AddressLine2))
                    {
                        profile.Address_Line_2 = userprofileviewmodel.AddressLine2;
                    }
                    profile.City         = userprofileviewmodel.City;
                    profile.State        = userprofileviewmodel.State;
                    profile.Zip_Code     = userprofileviewmodel.ZipCode;
                    profile.Country      = userprofileviewmodel.Country;
                    profile.University   = userprofileviewmodel.University;
                    profile.College      = userprofileviewmodel.College;
                    profile.ModifiedDate = DateTime.Now;
                    profile.ModifiedBy   = user.ID;

                    // check if loggedin user's profile picture is not null and user upload new profile picture then delete old one
                    if (userprofileviewmodel.ProfilePicture != null && profile.Profile_Picture != null)
                    {
                        string   path = Server.MapPath(profile.Profile_Picture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // if user upload profile picture then save it and store path in database
                    if (userprofileviewmodel.ProfilePicture != null)
                    {
                        string filename           = System.IO.Path.GetFileName(userprofileviewmodel.ProfilePicture.FileName);
                        string fileextension      = System.IO.Path.GetExtension(userprofileviewmodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + profile.User_ID + "/";
                        CreateDirectoryIfMissing(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        profile.Profile_Picture = profilepicturepath + newfilename;
                        userprofileviewmodel.ProfilePicture.SaveAs(path);
                    }

                    // update logged in user's profile and save
                    _dbcontext.Entry(profile).State = EntityState.Modified;
                    _dbcontext.SaveChanges();

                    // update first name and lastname and save
                    user.FirstName = userprofileviewmodel.FirstName;
                    user.LastName  = userprofileviewmodel.LastName;
                    _dbcontext.Entry(user).State = EntityState.Modified;
                    _dbcontext.SaveChanges();
                }
                // if profile is null then create user profile
                else
                {
                    // create new userprofile object
                    UserProfile userprofile = new UserProfile();

                    userprofile.User_ID = user.ID;
                    userprofile.DOB     = userprofileviewmodel.DOB;
                    userprofile.Gender  = userprofileviewmodel.Gender;
                    userprofile.Phone_number_Country_Code = userprofileviewmodel.PhoneNumberCountryCode;
                    userprofile.Phone_number   = userprofileviewmodel.PhoneNumber;
                    userprofile.Address_Line_1 = userprofileviewmodel.AddressLine1;
                    userprofile.Address_Line_2 = userprofileviewmodel.AddressLine2;
                    userprofile.City           = userprofileviewmodel.City;
                    userprofile.State          = userprofileviewmodel.State;
                    userprofile.Zip_Code       = userprofileviewmodel.ZipCode;
                    userprofile.Country        = userprofileviewmodel.Country;
                    userprofile.University     = userprofileviewmodel.University;
                    userprofile.College        = userprofileviewmodel.College;
                    userprofile.CreatedDate    = DateTime.Now;
                    userprofile.CreatedBy      = user.ID;

                    // if profile picture is not null then save it and store path in database with filename is timestamp
                    if (userprofileviewmodel.ProfilePicture != null)
                    {
                        string filename           = System.IO.Path.GetFileName(userprofileviewmodel.ProfilePicture.FileName);
                        string fileextension      = System.IO.Path.GetExtension(userprofileviewmodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + userprofile.User_ID + "/";
                        CreateDirectoryIfMissing(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        userprofile.Profile_Picture = profilepicturepath + newfilename;
                        userprofileviewmodel.ProfilePicture.SaveAs(path);
                    }

                    // save logged in user's profile
                    _dbcontext.UserProfile.Add(userprofile);
                    _dbcontext.SaveChanges();

                    // save firstname and lastname and save
                    user.FirstName = userprofileviewmodel.FirstName;
                    user.LastName  = userprofileviewmodel.LastName;
                    _dbcontext.Entry(user).State = EntityState.Modified;
                    _dbcontext.SaveChanges();
                }

                // if userprofile is created or edited then redirect to search page
                return(RedirectToAction("Search", "SearchNotes"));
            }
            // if ModelState is invalid then redirect to userProfile page
            else
            {
                userprofileviewmodel.CountryList = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                userprofileviewmodel.GenderList  = _dbcontext.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                return(View(userprofileviewmodel));
            }
        }
        public ActionResult MyProfile(AdminProfileModel obj)
        {
            // get logged in user
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                // get  logged in user profile
                var userprofile = context.Admin.Where(x => x.AdminID == user.ID).FirstOrDefault();

                if (userprofile != null)
                {
                    // check if secondary email is already exists in User or UserProfile table or not
                    // if email already exists then give error
                    bool secondaryemailalreadyexistsinusers       = context.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any();
                    bool secondaryemailalreadyexistsinuserprofile = context.Admin.Where(x => x.SecondaryEmailID == obj.Email && x.ID != user.ID).Any();
                    if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinuserprofile)
                    {
                        ModelState.AddModelError("SecondaryEmail", "This email address is already exists");
                        obj.CountryCodeList = context.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();
                        return(View(obj));
                    }

                    // update user's data
                    user.FirstName = obj.FirstName.Trim();
                    user.LastName  = obj.LastName.Trim();
                    // update userprofile's data
                    userprofile.SecondaryEmailID       = obj.SecondaryEmail.Trim();
                    userprofile.PhoneNumberCountryCode = obj.PhoneNumberCountryCode.Trim();
                    userprofile.Phone_number           = obj.PhoneNumber.Trim();

                    // user upploaded profile picture and there is also previous profile picture then delete previous profile picture
                    if (userprofile.Profile_Picture != null && obj.ProfilePicture != null)
                    {
                        string   path = Server.MapPath(userprofile.Profile_Picture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save new profile picture and update data in userprofile table
                    if (obj.ProfilePicture != null)
                    {
                        // get extension
                        string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName);
                        // set new name of file
                        string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        // set where to save picture
                        string profilepicturepath = "~/Members/" + userprofile.ID + "/";
                        // create directory if not exists
                        CreateDirectoryIfMissing(profilepicturepath);
                        // get physical path and save profile picture there
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        obj.ProfilePicture.SaveAs(path);
                        // save path in database
                        userprofile.Profile_Picture = profilepicturepath + newfilename;
                    }

                    // update userprofile's data
                    userprofile.ModifiedDate = DateTime.Now;
                    userprofile.ModifiedBy   = user.ID;

                    // update data and save data in database
                    context.Entry(user).State        = EntityState.Modified;
                    context.Entry(userprofile).State = EntityState.Modified;
                    context.SaveChanges();
                }
                else
                {
                    Admin admin_profile = new Admin();

                    admin_profile.AdminID = user.ID;


                    // check if secondary email is already exists in User or UserProfile table or not
                    // if email already exists then give error
                    bool secondaryemailalreadyexistsinusers       = context.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any();
                    bool secondaryemailalreadyexistsinuserprofile = context.Admin.Where(x => x.SecondaryEmailID == obj.Email && x.AdminID != user.ID).Any();
                    if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinuserprofile)
                    {
                        ModelState.AddModelError("SecondaryEmail", "This email address is already exists");
                        obj.CountryCodeList = context.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();
                        return(View(obj));
                    }

                    // update user's data
                    user.FirstName          = obj.FirstName.Trim();
                    user.LastName           = obj.LastName.Trim();
                    admin_profile.FirstName = obj.FirstName.Trim();
                    admin_profile.LastName  = obj.LastName.Trim();
                    admin_profile.EmailID   = obj.Email.Trim();
                    // update userprofile's data
                    admin_profile.SecondaryEmailID       = obj.SecondaryEmail.Trim();
                    admin_profile.PhoneNumberCountryCode = obj.PhoneNumberCountryCode.Trim();
                    admin_profile.Phone_number           = obj.PhoneNumber.Trim();
                    admin_profile.CreatedDate            = DateTime.Now;
                    admin_profile.CreatedBy = user.ID;

                    // user upploaded profile picture and there is also previous profile picture then delete previous profile picture
                    if (admin_profile.Profile_Picture != null && obj.ProfilePicture != null)
                    {
                        string   path = Server.MapPath(admin_profile.Profile_Picture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save new profile picture and update data in userprofile table
                    if (obj.ProfilePicture != null)
                    {
                        // get extension
                        string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName);
                        // set new name of file
                        string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        // set where to save picture
                        string profilepicturepath = "~/Members/" + admin_profile.ID + "/";
                        // create directory if not exists
                        CreateDirectoryIfMissing(profilepicturepath);
                        // get physical path and save profile picture there
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        obj.ProfilePicture.SaveAs(path);
                        // save path in database
                        admin_profile.Profile_Picture = profilepicturepath + newfilename;
                    }

                    context.Admin.Add(admin_profile);
                    context.SaveChanges();

                    // update userprofile's data


                    // update data and save data in database
                    context.Entry(user).State = EntityState.Modified;

                    // context.Entry(admin_profile).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Dashboard", "Admin"));
            }
            else
            {
                obj.CountryCodeList = context.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();

                return(View(obj));
            }
        }
Beispiel #8
0
        public ActionResult AddNotes(AddNotesViewModel addnotesmodel)
        {
            // check if upload note is null or not
            if (addnotesmodel.UploadNotes[0] == null)
            {
                ModelState.AddModelError("UploadNotes", "This field is required");
                return(View(addnotesmodel));
            }
            // check and raise error when note preview is null for paid notes
            if (addnotesmodel.IsPaid == true && addnotesmodel.NotesPreview == null)
            {
                ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                return(View(addnotesmodel));
            }
            // check model state
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNotes sellernotes = new SellerNotes();

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

                sellernotes.SellerID       = user.ID;
                sellernotes.Title          = addnotesmodel.Title;
                sellernotes.Status         = 6;
                sellernotes.Category       = addnotesmodel.Category;
                sellernotes.NoteType       = addnotesmodel.NoteType;
                sellernotes.NumberofPages  = addnotesmodel.NumberofPages;
                sellernotes.Description    = addnotesmodel.Description;
                sellernotes.UniversityName = addnotesmodel.UniversityName;
                sellernotes.Country        = addnotesmodel.Country;
                sellernotes.Course         = addnotesmodel.Course;
                sellernotes.CourseCode     = addnotesmodel.CourseCode;
                sellernotes.Professor      = addnotesmodel.Professor;
                sellernotes.IsPaid         = addnotesmodel.IsPaid;
                if (sellernotes.IsPaid)
                {
                    sellernotes.SellingPrice = addnotesmodel.SellingPrice;
                }
                else
                {
                    sellernotes.SellingPrice = 0;
                }
                sellernotes.CreatedDate = DateTime.Now;
                sellernotes.CreatedBy   = user.ID;
                sellernotes.IsActive    = true;

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

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

                // if display picture field is not null then save that picture into directory and save directory path into database
                if (addnotesmodel.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(addnotesmodel.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; //this is vertual path it is convert into physical path using Server.MapPath()

                    CreateDirectoryIfMissing(displaypicturepath);

                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    addnotesmodel.DisplayPicture.SaveAs(displaypicturefilepath);
                }

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

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

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

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

                        // save seller notes attachement
                        context.SellerNotesAttachements.Add(notesattachements);
                        context.SaveChanges();
                    }
                }

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

                return(View(Model));
            }
        }
Beispiel #9
0
        public ActionResult AddReview(SellerNotesReviews notereview)
        {
            // check if comment is null or not
            if (String.IsNullOrEmpty(notereview.Comments))
            {
                return(RedirectToAction("MyDownload"));
            }

            // check if rating is between 1 to 5
            if (notereview.Ratings < 1 || notereview.Ratings > 5)
            {
                return(RedirectToAction("MyDownload"));
            }

            // get Download object for check if user is downloaded note or not
            var notedownloaded = context.Downloads.Where(x => x.ID == notereview.AgainstDownloadsID && x.IsAttachmentDownloaded == true).FirstOrDefault();

            // user can provide review after downloading the note
            if (notedownloaded != null)
            {
                //get logged in user
                var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

                // check if user already provided review or not
                var alreadyprovidereview = context.SellerNotesReviews.Where(x => x.AgainstDownloadsID == notereview.AgainstDownloadsID && x.IsActive == true).FirstOrDefault();

                // if user not provide review then add review
                if (alreadyprovidereview == null)
                {
                    // create a sellernotesreview object and initialize it
                    SellerNotesReviews review = new SellerNotesReviews();

                    review.NoteID             = notereview.NoteID;
                    review.AgainstDownloadsID = notereview.AgainstDownloadsID;
                    review.ReviewedByID       = user.ID;
                    review.Ratings            = notereview.Ratings;
                    review.Comments           = notereview.Comments;
                    review.CreatedDate        = DateTime.Now;
                    review.CreatedBy          = user.ID;
                    review.IsActive           = true;

                    // save sellernotesreview into database
                    context.SellerNotesReviews.Add(review);
                    context.SaveChanges();

                    return(RedirectToAction("MyDownload"));
                }
                // if user is already provided review then edit it
                else
                {
                    alreadyprovidereview.Ratings      = notereview.Ratings;
                    alreadyprovidereview.Comments     = notereview.Comments;
                    alreadyprovidereview.ModifiedDate = DateTime.Now;
                    alreadyprovidereview.ModifiedBy   = user.ID;

                    // update review and save in database
                    context.Entry(alreadyprovidereview).State = EntityState.Modified;
                    context.SaveChanges();

                    return(RedirectToAction("MyDownload"));
                }
            }

            return(RedirectToAction("MyDownload"));
        }