Beispiel #1
0
        public async Task <ActionResult> AuthorRegister(AccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files[0];

                var uploadResult = ImageUploadHelper.GetUploadResult(file);

                var user = new ApplicationUser {
                    UserName = model.AuthorRegister.UserName, Email = model.AuthorRegister.Email, SSNImgId = uploadResult.PublicId, Avatar = Common.Constant.DefaultAvatarLink, Cover = Common.Constant.DefaultCoverLink
                };
                var result = await UserManager.CreateAsync(user, model.AuthorRegister.Password);

                if (result.Succeeded)
                {
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "[BookAholic]Xác Nhận Tài Khoản", "Chào mừng bạn đã đến với mạng xã hội sách BookAholic <p> Xin vui lòng click vào link để xác nhận tài khoản của bạn</p>: <a href=\"" + callbackUrl + "\">Xác Nhận tài khoản</a>");

                    ViewBag.Link = callbackUrl;

                    ViewBag.Message = "Kiểm tra Email để xác nhận tài khoản của bạn, bạn phải xác nhận tài khoản trước khi Đăng Nhập";
                    return(View("DisplayEmail"));
                }
                AddErrors(result);
            }
            ViewBag.sliders    = Context.Sliders.Find(_ => true).ToList();
            ViewBag.cloudinary = cloudinary;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Edit(Book book)
        {
            var listBook = Context.Books.Find(_ => true).ToList();

            foreach (var eachBook in listBook)
            {
                if (eachBook.BookName.ToLower().Equals(book.BookName.ToLower()) &&
                    listBook.Find(x => x.BookName.ToLower().Equals(book.BookName.ToLower())).Id != book.Id)
                {
                    ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
                }
            }
            if (ModelState.IsValid)
            {
                // TODO: Add update logic here
                //DangVH. Create. Start (02/11/2016)
                {
                    var file         = Request.Files[0];
                    var uploadResult = ImageUploadHelper.GetUploadResult(file);
                    //DangVH. Create. End (02/11/2016)
                    var editBook = Context.Books.Find(x => x.Id.Equals(new ObjectId(book.Id))).FirstOrDefault();
                    editBook.BookName    = book.BookName;
                    editBook.Authors     = book.Authors;
                    editBook.ReleaseDay  = book.ReleaseDay.ToLocalTime();
                    editBook.Description = book.Description;
                    if (file.ContentLength == 0)
                    {
                        editBook.ImgPublicId = book.ImgPublicId;
                    }
                    else
                    {
                        editBook.ImgPublicId = uploadResult.PublicId;
                    }
                    editBook.Categories.Clear();
                    //DangVH. Create. Start (14/11/2016)
                    editBook.Publishers.Clear();
                    foreach (var publisherId in book.Publishers)
                    {
                        editBook.Publishers.Add(publisherId);
                    }

                    foreach (var categoryId in book.Categories)
                    {
                        editBook.Categories.Add(categoryId);
                    }
                    //DangVH. Create. End (14/11/2016)
                    Context.Books.ReplaceOneAsync(x => x.Id.Equals(new ObjectId(book.Id)), editBook);
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            var selectedPublisherValue = book.Publishers.ToString();
            var selectedCategoryValue  = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            ViewBag.cloudinary  = cloudinary;
            return(View(book));
        }
        public ActionResult Upload(HttpPostedFileBase pubImage, string pubName, string pubAddress, string pubPhoneNo)
        {
            try
            {
                // Upload image to Cloudinary
                var           allPublisher = Context.Publishers.Find(_ => true).ToList();
                List <string> errorMessage = new List <string>();
                if (pubName == "" || pubName == null)
                {
                    var message = "Tên NXB không được để trống";
                    errorMessage.Add(message);
                }
                if (pubAddress == "" || pubAddress == null)
                {
                    var message = "Địa chỉ không được để trống";
                    errorMessage.Add(message);
                }
                if (pubImage == null)
                {
                    var message = "Ảnh NXB không được để trống";
                    errorMessage.Add(message);
                }
                foreach (var pub in allPublisher)
                {
                    if (pub.Name.ToLower().Equals(pubName.ToLower()))
                    {
                        var message = "Tên NXB đã tồn tại";
                        errorMessage.Add(message);
                    }
                }
                if (errorMessage.Count() == 0)
                {
                    var uploadResult = ImageUploadHelper.GetUploadResult(pubImage);

                    // Save new publisher to MongoDB
                    Publisher publisher = new Publisher()
                    {
                        ImagePublicId = uploadResult.PublicId,
                        Name          = pubName,
                        Address       = pubAddress,
                        PhoneNumber   = pubPhoneNo
                    };
                    Context.Publishers.InsertOneAsync(publisher);

                    return(Json(new {
                        success = "Thêm nhà xuất bản thành công"
                    }));
                }
                else
                {
                    return(Json(errorMessage, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json("Upload Failed. Error occurred. Error details: " + ex.Message));
            }
        }
Beispiel #4
0
        public ActionResult Create(Book book)
        {
            var listBook = Context.Books.Find(_ => true).ToList();
            var file     = Request.Files[0];

            if (file.ContentLength == 0)
            {
                ModelState.AddModelError("ImgPublicId", "Ảnh sách bắt buộc");
            }
            foreach (var eachBook in listBook)
            {
                if (book.BookName != null && eachBook.BookName.ToLower().Equals(book.BookName.ToLower()))
                {
                    ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
                }
            }
            if (ModelState.IsValid)
            {
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                var addBook      = new Book()
                {
                    BookName = book.BookName,
                    Authors  = book.Authors,
                    //DangVH. Delete. Start (14/11/2016)
                    //Publishers = book.Publishers,
                    //DangVH. Delete. End (14/11/2016)
                    ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                    Description = book.Description,
                    ImgPublicId = uploadResult.PublicId
                };
                foreach (var publisherId in book.Publishers)
                {
                    addBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    addBook.Categories.Add(categoryId);
                }
                //DangVH. Create. End (14/11/2016)
                Context.Books.InsertOneAsync(addBook);
                return(RedirectToAction("Index"));
            }
            //DangVH. Update. Start (14/11/2016)
            //Book newbook = BooksControllerHelper.GetCheckBoxValues();
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            var selectedPublisherValue = book.Publishers.ToString();
            var selectedCategoryValue  = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            //DangVH. Update. End (14/11/2016)
            return(View(book));
        }
        public ActionResult Upload(string desc)
        {
            try
            {
                //Configuration
                //DangVH. Delete. Start (02/11/2016)
                //Account account = new Account("dsddvwiqz", "677568653855233", "_RCoQNjMqr8Nt7-FAgs5T_guiWM");
                //var cloudinary = new Cloudinary(account);
                //var cloudinary = ImageUploadHelper.GetCloudinaryAccount();
                //DangVH. Delete. End (02/11/2016)
                var file = Request.Files[0];

                if (file == null)
                {
                    return(Json(new { result = false }));
                }
                //Upload Image
                //DangVH. Update. Start (01/11/2016)
                //var uploadParam = new ImageUploadParams()
                //{
                //    File = new FileDescription(file.FileName, file.InputStream),
                //};

                //var uploadResult = cloudinary.Upload(uploadParam);
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Update. End (01/11/2016)

                //Save photo (publicID) to MongoDB
                Slider mongoPhoto = new Slider()
                {
                    PublicId = uploadResult.PublicId,
                    Desc     = desc,
                    // HuyenPT. Create. Start. 06-12-2016
                    isShow = true,
                    // HuyenPT. Create. End. 06-12-2016
                };
                Context.Sliders.InsertOneAsync(mongoPhoto);

                return(Json("Đã thêm mới slide thành công!"));
            }
            catch
            {
                return(Json("Đã xảy ra lỗi"));
            }
        }
Beispiel #6
0
        public ActionResult Upload(string desc)
        {
            try
            {
                //Configuration
                //DangVH. Delete. Start (02/11/2016)
                //Account account = new Account("dsddvwiqz", "677568653855233", "_RCoQNjMqr8Nt7-FAgs5T_guiWM");
                //var cloudinary = new Cloudinary(account);
                //var cloudinary = ImageUploadHelper.GetCloudinaryAccount();
                //DangVH. Delete. End (02/11/2016)
                var file = Request.Files[0];

                if (file == null)
                {
                    return(Json(new { result = false }));
                }
                //Upload Image
                //DangVH. Update. Start (01/11/2016)
                //var uploadParam = new ImageUploadParams()
                //{
                //    File = new FileDescription(file.FileName, file.InputStream),
                //};

                //var uploadResult = cloudinary.Upload(uploadParam);
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Update. End (01/11/2016)

                //Save photo (publicID) to MongoDB
                Slider mongoPhoto = new Slider()
                {
                    PublicId = uploadResult.PublicId,
                    Desc     = desc
                };
                Context.Sliders.InsertOneAsync(mongoPhoto);

                return(Json("File Uploaded Successfully!"));
            }
            catch (Exception ex)
            {
                return(Json("Error occurred. Error details: " + ex.Message));
            }
        }
Beispiel #7
0
        public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                // TODO: Add insert logic here
                //var selectedCategories = book.Categories.Where(x => x.IsSelected).Select(x => x.CategoryId).ToList();
                //DangVH. Create. Start (01/11/2016)
                var file         = Request.Files[0];
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Create. End (01/11/2016)
                var addBook = new Book()
                {
                    BookName    = book.BookName,
                    Authors     = book.Authors,
                    ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                    Description = book.Description,
                    ImgPublicId = uploadResult.PublicId
                };

                foreach (var publisherId in book.Publishers)
                {
                    addBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    addBook.Categories.Add(categoryId);
                }
                //foreach (var categoryId in selectedCategories)
                //{
                //    addBook.Categories.Add(new BookCategoriesViewModel()
                //    {
                //        CategoryId = categoryId
                //    });
                //}
                Context.Books.InsertOneAsync(addBook);
                return(RedirectToAction("Index"));
            }
            //Book newbook = BooksControllerHelper.GetCheckBoxValues();
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            return(View());
        }
Beispiel #8
0
        public ActionResult Edit(Book book)
        {
            if (ModelState.IsValid)
            {
                // TODO: Add update logic here
                //DangVH. Create. Start (02/11/2016)
                var file         = Request.Files[0];
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Create. End (02/11/2016)
                //var selectedCategories = book.Categories.Where(x => x.IsSelected).Select(x => x.CategoryId).ToList();
                var editBook = Context.Books.Find(x => x.Id.Equals(new ObjectId(book.Id))).FirstOrDefault();
                editBook.BookName    = book.BookName;
                editBook.Authors     = book.Authors;
                editBook.ReleaseDay  = book.ReleaseDay.ToLocalTime();
                editBook.Description = book.Description;
                editBook.ImgPublicId = uploadResult.PublicId;
                editBook.Categories.Clear();
                editBook.Publishers.Clear();
                //foreach (var categoryId in selectedCategories)
                //{
                //    editBook.Categories.Add(new BookCategoriesViewModel()
                //    {
                //        CategoryId = categoryId
                //    });
                //}
                foreach (var publisherId in book.Publishers)
                {
                    editBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    editBook.Categories.Add(categoryId);
                }
                Context.Books.ReplaceOneAsync(x => x.Id.Equals(new ObjectId(book.Id)), editBook);
                return(RedirectToAction("Index"));
            }
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            return(View());
        }
Beispiel #9
0
        public ActionResult Upload(HttpPostedFileBase pubImage, string pubName, string pubAddress, string pubPhoneNo)
        {
            try
            {
                // Upload image to Cloudinary
                var uploadResult = ImageUploadHelper.GetUploadResult(pubImage);

                // Save new publisher to MongoDB
                Publisher publisher = new Publisher()
                {
                    ImagePublicId = uploadResult.PublicId,
                    Name          = pubName,
                    Address       = pubAddress,
                    PhoneNumber   = pubPhoneNo
                };
                Context.Publishers.InsertOneAsync(publisher);

                return(Json("File Uploaded Successfully!"));
            }
            catch (Exception ex)
            {
                return(Json("Upload Failed. Error occurred. Error details: " + ex.Message));
            }
        }
Beispiel #10
0
        public ActionResult ChangeImage(string id, HttpPostedFileBase file, int option)
        {
            try
            {
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                switch (option)
                {
                case 1:
                    var update1 = new BsonDocument("$set", new BsonDocument("AvaImg", uploadResult.PublicId));
                    Context.Groups.UpdateOneAsync(x => x.Id.Equals(new ObjectId(id)), update1);
                    break;

                case 2:
                    var update2 = new BsonDocument("$set", new BsonDocument("CoverImg", uploadResult.PublicId));
                    Context.Groups.UpdateOneAsync(x => x.Id.Equals(new ObjectId(id)), update2);
                    break;
                }
                return(Json("Đổi ảnh hoàn tất"));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
        public ActionResult Edit(string pubId, HttpPostedFileBase pubEditedImage, string pubEditedName, string pubEditedAddress, string pubEditedPhoneNo)
        {
            try
            {
                var           allPublisher = Context.Publishers.Find(_ => true).ToList();
                List <string> errorMessage = new List <string>();
                if (pubEditedName == "" || pubEditedName == null)
                {
                    var message = "Tên NXB không được để trống";
                    errorMessage.Add(message);
                }
                if (pubEditedAddress == "" || pubEditedAddress == null)
                {
                    var message = "Địa chỉ không được để trống";
                    errorMessage.Add(message);
                }
                foreach (var pub in allPublisher)
                {
                    if (pub.Name.ToLower().Equals(pubEditedName.ToLower()) &&
                        allPublisher.Find(x => x.Name.ToLower().Equals(pubEditedName.ToLower())).Id != pubId)
                    {
                        var message = "Tên NXB đã tồn tại";
                        errorMessage.Add(message);
                    }
                }
                if (errorMessage.Count() == 0)
                {
                    var filter = Builders <Publisher> .Filter.Eq(x => x.Id, pubId);

                    // Check if user change image or not
                    if (pubEditedImage == null)
                    {
                        var update = Builders <Publisher> .Update.
                                     Set(x => x.Name, pubEditedName).Set(x => x.Address, pubEditedAddress).
                                     Set(x => x.PhoneNumber, pubEditedPhoneNo);

                        Context.Publishers.FindOneAndUpdate(filter, update);
                    }
                    else
                    {
                        // Upload image to Cloudinary
                        var uploadResult = ImageUploadHelper.GetUploadResult(pubEditedImage);
                        var update       = Builders <Publisher> .Update.Set(x => x.ImagePublicId, uploadResult.PublicId).
                                           Set(x => x.Name, pubEditedName).Set(x => x.Address, pubEditedAddress).
                                           Set(x => x.PhoneNumber, pubEditedPhoneNo);

                        Context.Publishers.FindOneAndUpdate(filter, update);
                    }
                    return(Json(new {
                        success = "Chỉnh sửa thông tin nhà xuất bản thành công!"
                    }));
                }
                else
                {
                    return(Json(errorMessage, JsonRequestBehavior.AllowGet));
                }
            }
            catch
            {
                return(Json("Rất tiếc! Đã xảy ra lỗi trong quá trình xử lý"));
            }
        }
Beispiel #12
0
 public ActionResult Create(Book book)
 {
     if (Context.Users.Find(x => x.Id.Equals(User.Identity.GetUserId())).FirstOrDefault().Roles.Contains("admin"))
     {
         var listBook = Context.Books.Find(_ => true).ToList();
         var file     = Request.Files[0];
         if (file.ContentLength == 0)
         {
             ModelState.AddModelError("ImgPublicId", "Ảnh sách bắt buộc");
         }
         foreach (var eachBook in listBook)
         {
             if (book.BookName != null && eachBook.BookName.ToLower().Equals(book.BookName.ToLower()))
             {
                 ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
             }
         }
         if (book.Authors.Count == 0)
         {
             ModelState.AddModelError("Authors", "Tác giả bắt buộc");
         }
         if (book.Categories.Count == 0)
         {
             ModelState.AddModelError("Categories", "Thể loại sách bắt buộc");
         }
         if (book.Publishers.Count == 0)
         {
             ModelState.AddModelError("Publishers", "Nhà xuất bản bắt buộc");
         }
         if (ModelState.IsValid)
         {
             var uploadResult = ImageUploadHelper.GetUploadResult(file);
             var addBook      = new Book()
             {
                 BookName    = book.BookName,
                 ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                 Description = book.Description,
                 ImgPublicId = uploadResult.PublicId,
                 Requested   = false,
                 Text        = CommonHelper.SearchString(book.BookName.ToLower())
             };
             foreach (var publisherId in book.Publishers)
             {
                 addBook.Publishers.Add(publisherId);
             }
             foreach (var categoryId in book.Categories)
             {
                 addBook.Categories.Add(categoryId);
             }
             foreach (var authorId in book.Authors)
             {
                 addBook.Authors.Add(authorId);
             }
             //DangVH. Create. End (14/11/2016)
             Context.Books.InsertOneAsync(addBook);
             return(RedirectToAction("Index"));
         }
         //DangVH. Update. Start (14/11/2016)
         //Book newbook = BooksControllerHelper.GetCheckBoxValues();
         ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
         var selectedPublisherValue = book.Publishers.ToString();
         var selectedCategoryValue  = book.Categories.ToString();
         var selectedAuthorValue    = book.Authors.ToString();
         ViewBag.publisherId = GetPubsCatsAus(selectedPublisherValue.Split(','), 1);
         ViewBag.categoryId  = GetPubsCatsAus(selectedCategoryValue.Split(','), 2);
         ViewBag.authorId    = GetPubsCatsAus(selectedAuthorValue.Split(','), 3);
         //DangVH. Update. End (14/11/2016)
         return(View(book));
     }
     else
     {
         ViewBag.errorMessage = "Bạn không có quyền truy cập vào chức năng này";
         return(View("NotFoundError"));
     }
 }