コード例 #1
0
        public ActionResult ChangeCover(String userId, HttpPostedFileBase image)
        {
            var service = this.Service <IAspNetUserService>();

            ResponseModel <String> response = null;

            FileUploader uploader = new FileUploader();

            try
            {
                String path = null;

                if (image != null)
                {
                    path = uploader.UploadImage(image, userImagePath);
                }


                String result = service.ChangeCover(userId, path);

                response = new ResponseModel <String>(true, "Ảnh bìa của bạn đã được cập nhật!", null, result);
            }
            catch (Exception)
            {
                response = ResponseModel <String> .CreateErrorResponse("Ảnh bìa của bạn chưa được cập nhật!", systemError);
            }

            return(Json(response));
        }
コード例 #2
0
        public ActionResult ChangeGroupAvatar(int groupId, HttpPostedFileBase image)
        {
            var service = this.Service <IGroupService>();

            ResponseModel <String> response = null;

            FileUploader uploader = new FileUploader();

            try
            {
                String path = null;

                if (image != null)
                {
                    path = uploader.UploadImage(image, userImagePath);
                }

                String result = service.ChangeAvatarImage(groupId, path);

                response = new ResponseModel <String>(true, "Ảnh nhóm đã được cập nhật!", null, result);
            }
            catch (Exception)
            {
                response = ResponseModel <String> .CreateErrorResponse("Ảnh nhóm chưa được cập nhật!", systemError);
            }

            return(Json(response));
        }
コード例 #3
0
        public ActionResult CreateGroup(GroupCreateModel model, String userId)
        {
            var groupService = this.Service <IGroupService>();

            var groupMemberService = this.Service <IGroupMemberService>();

            ResponseModel <GroupViewModel> response = null;

            try {
                Group group = Mapper.Map <Group>(model);

                if (model.UploadImage != null)
                {
                    FileUploader uploader = new FileUploader();

                    group.Avatar = uploader.UploadImage(model.UploadImage, userImagePath);
                }

                group = groupService.CreateGroup(group);

                groupMemberService.CreateGroupAdmin(group.Id, userId);

                GroupViewModel result = Mapper.Map <GroupViewModel>(group);

                response = new ResponseModel <GroupViewModel>(true, "Tạo nhóm thành công", null, result);
            } catch (Exception) {
                response = ResponseModel <GroupViewModel> .CreateErrorResponse("Tạo nhóm thất bại!", systemError);
            }

            return(Json(response));
        }
コード例 #4
0
        public JsonResult Edit(NewsViewModel model, HttpPostedFileBase ImageFile)
        {
            var result = new AjaxOperationResult();

            if (ModelState.IsValid)
            {
                var service = this.Service <INewsService>();
                var news    = service.Get(q => q.Id == model.Id).SingleOrDefault();
                if (news != null)
                {
                    var uploader = new FileUploader();

                    if (ImageFile != null)
                    {
                        news.Image = uploader.UploadImage(ImageFile, userImagePath);
                    }
                    news.Title       = model.Title;
                    news.NewsContent = model.NewsContent;
                    news.CategoryId  = model.CategoryId;

                    service.Update(news);
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
コード例 #5
0
        private async Task CreateTest(TestModel testModel, IFormFile image)
        {
            var test = new TestEntity
            {
                Name      = testModel.Name,
                IsActive  = true,
                Questions = testModel.Questions.Select(question => new QuestionEntity
                {
                    Message          = question.Message,
                    SelectedAnswerId = question.SelectedAnswerId,
                    Answers          = question.Answers.Select(answer => new AnswerEntity
                    {
                        Id      = answer.Id,
                        Message = answer.Message
                    }).ToList()
                }).ToList()
            };

            if (image != null)
            {
                test.ImagePath = await FileUploader.UploadImage(image, appEnvironment);
            }

            await testRepository.CreateAsync(test);

            TempData["Success"] = $"\"{test.Name}\" успешно сохранён";
        }
コード例 #6
0
        public string saveEvtImage(HttpPostedFileBase image)
        {
            string       containFolder        = "EventImages";
            FileUploader _fileUploaderService = new FileUploader();

            string path = _fileUploaderService.UploadImage(image, containFolder);

            return(path);
        }
コード例 #7
0
        public async Task <IActionResult> EditDeliveryMan(DeliveryMenViewModel dvm, IFormFile file)
        {
            var deliveryMan         = deliveryManService.GetDeliveryManById(dvm.DeliveryMan.Id);
            var deliveryManLocation = locationService.GetLocationById(dvm.DeliveryMan.Location.Id);

            deliveryMan.FirstName       = dvm.DeliveryMan.FirstName;
            deliveryMan.LastName        = dvm.DeliveryMan.LastName;
            deliveryMan.Phone           = dvm.DeliveryMan.Phone;
            deliveryManLocation.Address = dvm.DeliveryMan.Location.Address;
            deliveryManLocation.City    = dvm.DeliveryMan.Location.City;
            deliveryManLocation.ZipCode = dvm.DeliveryMan.Location.ZipCode;

            if (file != null)
            {
                //The picture has been changed
                //Upload the new picture
                var picturePath  = FileUploader.UploadImage(file, "DeliveryMenPictures");
                var pictureBytes = FileUploader.FileToBase64(picturePath);

                deliveryMan.PicturePath = picturePath;
                deliveryMan.ImageBase64 = pictureBytes;
            }

            if (deliveryMan.Email != dvm.DeliveryMan.Email)
            {
                //Email has been updated
                var user = await _userManager.FindByIdAsync(deliveryMan.IdentityId);

                if (user != null)
                {
                    user.Email                    = dvm.DeliveryMan.Email;
                    user.NormalizedEmail          = dvm.DeliveryMan.Email.ToUpper();
                    user.UserName                 = dvm.DeliveryMan.Email;
                    user.NormalizedUserName       = dvm.DeliveryMan.Email.ToUpper();
                    deliveryMan.Email             = dvm.DeliveryMan.Email;
                    deliveryMan.HasValidatedEmail = true;

                    await _userManager.UpdateAsync(user);
                }
            }


            deliveryMan.Location = deliveryManLocation;
            locationService.UpdateLocation(deliveryManLocation);
            deliveryManService.EditDeliveryMan(deliveryMan);


            TempData["Message"] = "Livreur modifié avec succès !";

            return(RedirectToAction("AllDeliveryMen"));
        }
コード例 #8
0
        public void saveImage(int id, IEnumerable <HttpPostedFileBase> images)
        {
            string     containFolder          = "FieldImages";
            FieldImage fi                     = null;
            List <HttpPostedFileBase> li      = images.ToList();
            FileUploader _fileUploaderService = new FileUploader();

            foreach (var item in li)
            {
                string filePath = _fileUploaderService.UploadImage(item, containFolder);
                fi         = new FieldImage();
                fi.FieldId = id;
                fi.Image   = filePath;
                this.Create(fi);
                this.Save();
            }
        }
コード例 #9
0
        public void saveImage(int id, IEnumerable <HttpPostedFileBase> uploadImages)
        {
            string     containFolder        = "PlaceImages";
            PlaceImage pi                   = null;
            List <HttpPostedFileBase> ui    = uploadImages.ToList();
            FileUploader _fileUploadService = new FileUploader();

            for (int i = 0; i < ui.Count; i++)
            {
                string filePath = _fileUploadService.UploadImage(ui[i], containFolder);
                pi         = new PlaceImage();
                pi.PlaceId = id;
                pi.Image   = filePath;
                this.Create(pi);
                this.Save();
            }
        }
コード例 #10
0
        public IActionResult AddCategory([Bind("Name,Description")] Category category, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                string path = FileUploader.UploadImage(file, "CategoriesImages");

                //Convert to Base64
                byte[] base64 = FileUploader.FileToBase64(path);

                category.ImagePath   = path;
                category.ImageBase64 = base64;

                categoryService.AddCategory(category);
                TempData["Message"] = "Catégorie ajoutée avec succès !";
                return(RedirectToAction("AllCategories"));
            }
            return(View());
        }
コード例 #11
0
        private async Task EditExistingTest(TestEntity existingTest, TestModel test, IFormFile image)
        {
            existingTest.Name = test.Name;

            if (image != null)
            {
                existingTest.ImagePath = await FileUploader.UploadImage(image, appEnvironment);
            }

            foreach (var question in test.Questions)
            {
                var existingQuestion = FindQuestionById(question.Id, existingTest);
                if (existingQuestion == null)
                {
                    continue;
                }

                EditExistingQuestion(existingQuestion, question);
            }
        }
コード例 #12
0
        public IActionResult EditCategory([Bind("Name, Description")] Category category, int Id, IFormFile file)
        {
            string imagePath = FileUploader.UploadImage(file, "CategoriesImages");

            //Convert to Base64
            byte[] base64 = FileUploader.FileToBase64(imagePath);

            var editedCategory = new Category
            {
                Description = category.Description,
                Id          = Id,
                ImagePath   = imagePath,
                Name        = category.Name,
                ImageBase64 = base64
            };

            categoryService.EditCategory(editedCategory);
            TempData["Message"] = "Catégorie modifiée avec succès !";

            return(RedirectToAction("AllCategories"));
        }
コード例 #13
0
        public ActionResult UpdateComment(int commentId, String content, HttpPostedFileBase image, bool deleteOldImg)
        {
            var result = new AjaxOperationResult();

            var service = this.Service <IPostCommentService>();

            PostComment comment = service.FirstOrDefaultActive(x => x.Id == commentId);

            if (comment != null)
            {
                comment.Comment = content;

                if (image != null)
                {
                    FileUploader uploader = new FileUploader();

                    comment.Image = uploader.UploadImage(image, containingFolder);
                }
                else
                {
                    if (deleteOldImg)
                    {
                        comment.Image = null;
                    }
                }

                service.Update(comment);
                service.Save();
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }


            return(Json(result));
        }
コード例 #14
0
        public ActionResult ChangeAvatarImage(int groupId, HttpPostedFileBase inputAvatar)
        {
            string containingFolder = "AvatarImages";
            var    result           = new AjaxOperationResult();
            var    _groupService    = this.Service <IGroupService>();

            Group group = _groupService.FirstOrDefaultActive(u => u.Id == groupId);

            if (group != null && inputAvatar != null)
            {
                FileUploader _fileUploadService = new FileUploader();
                string       filePath           = _fileUploadService.UploadImage(inputAvatar, containingFolder);
                group.Avatar = filePath;
                _groupService.UpdateGroup(group);
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
コード例 #15
0
        public ActionResult ChangeAvatarImage(string userId, HttpPostedFileBase inputAvatar)
        {
            string containingFolder = "AvatarImages";
            var    result           = new AjaxOperationResult();
            var    _userService     = this.Service <IAspNetUserService>();

            AspNetUser user = _userService.FirstOrDefaultActive(u => u.Id.Equals(userId));

            if (user != null && inputAvatar != null)
            {
                FileUploader _fileUploadService = new FileUploader();
                string       filePath           = _fileUploadService.UploadImage(inputAvatar, containingFolder);
                user.AvatarImage = filePath;
                _userService.UpdateUser(user);
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
コード例 #16
0
 public IActionResult AddImage(IFormFile image)
 {
     if (image != null && image.Length > 0)
     {
         var host         = _hostingEnvironment.WebRootPath;
         var url          = _settings.GetSection("ProductImages").Value;
         var savePath     = Path.Combine(host, url);
         var uploadResult = FileUploader.UploadImage(image, savePath, compression: 70, width: 512, height: 512);
         if (!uploadResult.succsseded)
         {
             return(Json(false));
         }
         else
         {
             var img = uploadResult.result;
             return(Json("/Uploads/ProductImages/" + img));
         }
     }
     else
     {
         return(Json(false));
     }
 }
コード例 #17
0
        public JsonResult Create(NewsViewModel model, HttpPostedFileBase ImageFile)
        {
            var result = new AjaxOperationResult();

            if (ModelState.IsValid)
            {
                var service  = this.Service <INewsService>();
                var uploader = new FileUploader();

                model.CreateDate = DateTime.Now;
                model.UserId     = User.Identity.GetUserId();
                if (ImageFile != null)
                {
                    model.Image = uploader.UploadImage(ImageFile, userImagePath);
                }
                var entity = model.ToEntity();
                service.Create(entity);
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
コード例 #18
0
        public ActionResult PostOnTimeLine(PostUploadViewModel model, string profileId)
        {
            var service = this.Service <IPostService>();

            var aspNetUserService = this.Service <IAspNetUserService>();

            var notiService = this.Service <INotificationService>();

            var memberService = this.Service <IGroupMemberService>();

            PostOveralViewModel result = null;

            ResponseModel <PostOveralViewModel> response = null;

            try
            {
                Post post = Mapper.Map <Post>(model);
                post.ProfileId = profileId;
                if (model.PostContent == null)
                {
                    post.PostContent = "";
                }
                post.ContentType = GetPostType(model);

                if (post.ContentType != int.Parse(ContentPostType.TextOnly.ToString("d")))
                {
                    FileUploader uploader = new FileUploader();

                    foreach (var img in model.UploadImage)
                    {
                        PostImage image = new PostImage();

                        image.Image = uploader.UploadImage(img, userImagePath);

                        post.PostImages.Add(image);
                    }
                }

                post = service.CreatePost(post);

                ////Notify all group members
                //if (post.GroupId != null)
                //{
                //    List<GroupMember> memberList = GetMemberList(post.GroupId);

                //    AspNetUser postedUser = aspNetUserService.FindUser(post.UserId);

                //    foreach (var member in memberList)
                //    {
                //        if (!(member.UserId.Equals(post.UserId)))
                //        {
                //            Notification noti = notiService.SaveNoti(member.UserId, post.UserId, "Post", postedUser.FullName + " đã đăng một bài viết", (int)NotificationType.Post, post.Id, null, null);

                //            List<string> registrationIds = GetToken(member.UserId);

                //            if (registrationIds != null && registrationIds.Count != 0)
                //            {
                //                NotificationModel notiModel = Mapper.Map<NotificationModel>(PrepareNotificationViewModel(noti));

                //                Android.Notify(registrationIds, null, notiModel);
                //            }
                //        }
                //    }
                //}

                if (post.UserId != profileId)
                {
                    var _notificationService = this.Service <INotificationService>();
                    var _userService         = this.Service <IAspNetUserService>();

                    AspNetUser sender = _userService.FindUser(post.UserId);

                    string title   = Utils.GetEnumDescription(NotificationType.Post);
                    int    type    = (int)NotificationType.Post;
                    string message = sender.FullName + " đã đăng một bài viết lên tường nhà bạn";

                    Notification noti = _notificationService.CreateNoti(profileId, post.UserId, title, message, type, post.Id, null, null, null);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);
                }

                //Missing post sport

                result = Mapper.Map <PostOveralViewModel>(post);

                result.AspNetUser = Mapper.Map <AspNetUserSimpleModel>(aspNetUserService.FindUser(result.UserId));

                PreparePostOveralData(result, post.UserId);

                response = new ResponseModel <PostOveralViewModel>(true, "Đăng bài thành công!", null, result);
            }
            catch (Exception)
            {
                response = ResponseModel <PostOveralViewModel> .CreateErrorResponse("Đăng bài thất bại!", systemError);
            }

            return(Json(response));
        }
コード例 #19
0
        public ActionResult Comment(int postId, String userId, String content, HttpPostedFileBase image)
        {
            var service = this.Service <IPostCommentService>();

            var notiService = this.Service <INotificationService>();

            var postService = this.Service <IPostService>();

            var aspNetUserService = this.Service <IAspNetUserService>();

            var likeService = this.Service <ILikeService>();

            ResponseModel <PostCommentDetailViewModel> response = null;

            try
            {
                String commentImage = null;

                if (image != null)
                {
                    FileUploader uploader = new FileUploader();

                    commentImage = uploader.UploadImage(image, userImagePath);
                }

                PostComment comment = service.Comment(postId, userId, content, commentImage);

                AspNetUser commentedUser = aspNetUserService.FindUser(comment.UserId);

                Post post = postService.GetPostById(comment.PostId);

                AspNetUser user = postService.GetUserNameOfPost(post.Id);

                List <string> AllRelativeUserIdOfPost = new List <string>();

                List <PostComment> listPostCmt = service.GetAllRelativeCmtDistinct(postId).ToList();

                List <Like> listPostLike = likeService.GetAllRelativeLikeDistinct(postId).ToList();

                foreach (var item in listPostCmt)
                {
                    AllRelativeUserIdOfPost.Add(item.UserId);
                }

                foreach (var item in listPostLike)
                {
                    AllRelativeUserIdOfPost.Add(item.UserId);
                }

                AllRelativeUserIdOfPost = AllRelativeUserIdOfPost.Distinct().ToList();

                //Noti to post creator
                if (!(post.UserId.Equals(commentedUser.Id)))
                {
                    string       u  = post.UserId;
                    string       u1 = commentedUser.Id;
                    Notification notiForPostCreator = notiService.SaveNoti(u, u1, "Comment", commentedUser.FullName + " đã bình luận về bài viết của bạn", int.Parse(NotificationType.Post.ToString("d")), post.Id, null, null);

                    //Fire base noti
                    List <string> registrationIds = GetToken(user.Id);

                    //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                    NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(notiForPostCreator));

                    if (registrationIds != null && registrationIds.Count != 0)
                    {
                        Android.Notify(registrationIds, null, model);
                    }


                    //SignalR Noti
                    NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(notiForPostCreator));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                }

                //noti to all user that relavtive in this post
                foreach (var item in AllRelativeUserIdOfPost)
                {
                    if (!(item.Equals(commentedUser.Id)) && !(item.Equals(post.UserId)))
                    {
                        string       i   = item;
                        string       i1  = commentedUser.Id;
                        Notification not = notiService.SaveNoti(item, commentedUser.Id, "Comment", commentedUser.FullName + " đã bình luận về bài viết mà bạn theo dõi", int.Parse(NotificationType.Post.ToString("d")), post.Id, null, null);

                        Notification noti = notiService.FirstOrDefaultActive(n => n.Id == not.Id);

                        //Fire base noti
                        List <string> registrationIds = GetToken(item);

                        //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                        NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                        if (registrationIds != null && registrationIds.Count != 0)
                        {
                            Android.Notify(registrationIds, null, model);
                        }


                        //SignalR Noti
                        NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                        // Get the context for the Pusher hub
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                        // Notify clients in the group
                        hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                    }
                }



                PostCommentDetailViewModel result = PreparePostCommentDetailViewModel(comment);

                response = new ResponseModel <PostCommentDetailViewModel>(true, "Bình luận thành công", null, result);
                post.LatestInteractionTime = DateTime.Now;
                postService.Update(post);
                postService.Save();
            }
            catch (Exception)
            {
                response = ResponseModel <PostCommentDetailViewModel> .CreateErrorResponse("Bình luận thất bại", systemError);
            }
            return(Json(response));
        }
コード例 #20
0
        public async Task <IActionResult> Register([Bind("FirstName, LastName, Email, Password, Phone, Address, City, ZipCode")] RegisterViewModel model, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (await _userManager.FindByEmailAsync(model.Email) != null)
            {
                TempData["ErrorMessage"] = "Email déjà utilisé !";
                return(View());
            }

            var result = await _userManager.CreateAsync(new IdentityUser
            {
                Email    = model.Email,
                UserName = model.Email
            }, model.Password);

            if (result.Succeeded)
            {
                var location = locationService.AddLocation(new Location
                {
                    Address = model.Address,
                    City    = model.City,
                    ZipCode = model.ZipCode
                });

                var user = await _userManager.FindByEmailAsync(model.Email);

                string picturePath = "~/Content/AdminPictures/defaultAvatar.jpg";
                if (file != null)
                {
                    //Upload image
                    picturePath = FileUploader.UploadImage(file, "AdminPictures");
                }

                var admin = new Admin
                {
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    Email             = model.Email,
                    Phone             = model.Phone,
                    Location          = location,
                    HasValidatedEmail = false,
                    IdentityId        = user.Id,
                    PicturePath       = picturePath
                };

                adminService.AddAdmin(admin);

                TempData["Message"] = "Inscription effectuée. Vous allez recevoir un email pour valider votre compte.";
                //Send Verification Email
                var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                SendVerificationEmail(admin, user.Id, token, false);

                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["ErrorMessage"] = result.Errors.ToString();
                return(View());
            }
        }