public async Task <IActionResult> UpdateProfilePicture(PreviewUserViewModel input, IFormFile ProfilePicture)
        {
            if (ModelState.IsValid)
            {
                input.Id = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                await userService.UpdateProfilePicture(input, ProfilePicture);

                return(RedirectToAction("PreviewUser", "Users", new { id = input.Id }));
            }
            else
            {
                return(this.View(input));
            }
        }
示例#2
0
        public async Task <string> UpdateProfilePicture(PreviewUserViewModel input, IFormFile ProfilePicture)
        {
            if (ProfilePicture.Length > 0)
            {
                using (var stream = new MemoryStream())
                {
                    await ProfilePicture.CopyToAsync(stream);

                    input.ProfilePicture = stream.ToArray();
                }
            }

            PhotographyAddictedUser user = userDbset.All().FirstOrDefault(i => i.Id == input.Id);

            user.ProfilePicture = input.ProfilePicture;
            await userDbset.SaveChangesAsync();

            return(user.Id);
        }
示例#3
0
        public void CreateFanfic([FromBody] FanficScriptModel data)
        {
            string userId             = User.Identity.GetUserId();
            PreviewUserViewModel user = Mapper
                                        .Map <PreviewUserViewModel>(ApplicationUserRepository.GetApplicationUserById(data.UserId));

            if (user != null && User.IsInRole("admin"))
            {
                userId = user.Id;
            }
            Fanfic fanfic = new Fanfic
            {
                ApplicationUserId = userId,
                AverageRating     = 0,
                CategoryId        = data.Category,
                CreateDate        = DateTime.Now,
                Description       = data.Description,
                ImgUrl            = data.ImgUrl,
                Name = data.Name
            };
            int id = FanficRepository.AddFanfic(fanfic);

            foreach (var topicScript in data.Topics)
            {
                Topic topic = new Topic
                {
                    Name          = topicScript.Name,
                    Number        = topicScript.Number,
                    FanficId      = id,
                    Text          = topicScript.Text,
                    ImgUrl        = topicScript.ImgUrl,
                    AverageRating = 0
                };
                TopicRepository.AddTopic(topic);
            }
            foreach (var tag in data.Tags)
            {
                FanficTagRepository.AddNewFanficTag(id, TagRepository.FindOrAdd(tag.Name));
            }
        }