コード例 #1
0
        public ImageMessageModel SendImageMessage(User sender, uint chatId, IFormFile uploadedFile)
        {
            var chat = _repository.GetChat(chatId);

            ValidateUserInChat(chat, sender.Name);
            var fileInfo = _fileService.AddImage(uploadedFile);
            var message  = new ImageMessage {
                Date = DateTime.UtcNow, FromUser = sender, Image = fileInfo
            };

            _repository.AddMessage(chat, message);
            _updatesService.NotifyAddMessage(message, chat);
            return(ImageMessageToModel(message));
        }
コード例 #2
0
        public async Task <IActionResult> ChangeImage(ChangeImageViewModel model)
        {
            User currentUser = await userService.GetCurrentUserAsync(HttpContext);

            if (ModelState.IsValid && (model.UserId == currentUser.Id || User.IsInRole("Admin")))
            {
                var newImage = await fileService.AddImage(model.Image);

                var result = await profileService.ChangeImage(model.UserId, newImage);

                if (result.Succedeed)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(BadRequest());
        }