Пример #1
0
        public ActionResult Add(PictureInputModel model)
        {
            if (ModelState.IsValid)
            {
                string urlToSaveInDb = this.SavePic(model.Picture);
                if (urlToSaveInDb != null)
                {
                    var picture = new Picture()
                    {
                        Title = model.Title,
                        Url   = urlToSaveInDb,
                    };
                    this.Data.Pictures.Add(picture);
                    this.Data.SaveChanges();

                    return(this.RedirectToAction("Add", "Home"));
                }
                else
                {
                    this.ModelState.AddModelError(string.Empty, "Error while saving picture!");
                }
            }

            return(this.View(model));
        }
Пример #2
0
        public async Task <bool> CreatePerformence(PerformenceCreateInputModel inputModel, ApplicationUser user)
        {
            Performence performence = AutoMapper.Mapper.Map <Performence>(inputModel);

            if (performence == null)
            {
                return(false);
            }

            performence.ArtistId = user.ArtistId;

            var pictureName = performence.Id;

            var pictureUrl = await this.cloudinaryService.UploadPictureAsync(inputModel.PerformencePhoto, pictureName);

            performence.PerformencePhoto.Title       = pictureName;
            performence.PerformencePhoto.Link        = pictureUrl;
            performence.PerformencePhoto.Description = inputModel.Description;

            PictureInputModel picture = AutoMapper.Mapper.Map <PictureInputModel>(performence.PerformencePhoto);

            var pictureId = await this.fileService.AddPictureToDb(picture);

            performence.PerformencePhotoId = pictureId;

            await this.performenceRepository.AddAsync(performence);

            await this.performenceRepository.SaveChangesAsync();

            bool result = await this.artistService.SetPerformenceAsync(user.ArtistId, performence);

            return(result);
        }
Пример #3
0
        public async Task <IActionResult> UploadPicture(PictureInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            string name = input.AlbumName.Replace(" ", "-");

            await this.cloudinaryService.AddPhotoInAlbum(input.AlbumId, input.File);

            return(this.RedirectToAction(nameof(this.ByName), new { name }));
        }
Пример #4
0
        public async Task <string> AddPictureToDb(PictureInputModel picture)
        {
            // TODO: Refactor this;
            string picTransform = @"/$w_300,$h_200,$ar_1.45/w_$w,ar_$ar,c_fill,g_face";
            var    pic          = new Picture {
                Link = picture.Link.Insert(46, picTransform), Description = picture.Description, Title = picture.Title, UploadDate = DateTime.UtcNow
            };

            await this.context.AddAsync(pic);

            await this.context.SaveChangesAsync();

            return(pic.Id);
        }
Пример #5
0
        public async Task <IActionResult> OnPostRegisterAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? this.Url.Content("~/");
            if (this.ModelState.IsValid)
            {
                var name = this.User.Identity.Name;

                var user = this.userService.GetApplicationUserByName(name);

                var social = new Social()
                {
                    WebSite = string.Empty, Facebook = string.Empty, Youtube = string.Empty
                };

                var artist = new Artist()
                {
                    AboutMe    = this.Input.AboutMe,
                    CategoryId = await this.categoryService.GetCategoryIdAsync(this.Input.Category),
                    Nikname    = this.Input.Nikname,
                    WorkNumber = this.Input.WorkNumber,
                    Social     = social,
                    SocialId   = social.Id,
                };

                this.userService.AddArtistSettings(user, artist);

                if (this.Input.Picture != null)
                {
                    var    pictureName = this.Input.Nikname + GlobalConstants.ProfilePicture;
                    string pictureLink = await this.cloudinaryService.UploadPictureAsync(this.Input.Picture, pictureName);

                    var picture = new PictureInputModel()
                    {
                        Link = pictureLink, Title = user.UserName, Description = this.Input.AboutMe
                    };
                    var pictureToDb = await this.picureService.AddPictureToDb(picture, user);

                    bool isGenerate = await this.picureService.SetArtistPicture(picture, user);
                }
                return(this.Redirect(GlobalConstants.HomeUrl));
            }

            return(this.Forbid());
            //TODO: Iplement Logic
            // If we got this far, something failed, redisplay form
        }
Пример #6
0
        public async Task <bool> SetArtistPicture(PictureInputModel picture, ApplicationUser user)
        {
            var newPic = new Picture()
            {
                Link = picture.Link, Title = picture.Title, Description = picture.Description
            };

            await this.context.AddAsync(newPic);

            await this.context.SaveChangesAsync();

            user.Artist.ProfilePicture = newPic;
            int result = await this.userRepository.SaveChangesAsync();

            if (result > 0)
            {
                return(true);
            }

            return(false);
        }
        public ActionResult Create(PictureInputModel model, int id)
        {
            var contest = this.Data.Contests.GetById(id);

            if (contest.Type == ContestType.Private && !contest.Participants.Contains(this.UserProfile) &&
                contest.Type == ContestType.Private && contest.Owner != this.UserProfile)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "The contest is private. You need to be invited by the owner.");
            }

            if (contest.IsDeleted || contest.IsClosedForSubmissions)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "The contest is closed for submissions.");
            }

            string path = Dropbox.Upload(model.Photo.FileName, this.UserProfile.UserName, model.Photo.InputStream);

            var picture = new Picture()
            {
                Title = model.Title,
                Url = path,
                Owner = this.UserProfile,
                CreatedOn = DateTime.Now,
                ContestId = id,
                IsDeleted = false
            };

            this.Data.Pictures.Add(picture);

            if (!contest.Participants.Contains(this.UserProfile))
            {
                contest.Participants.Add(this.UserProfile);
            }

            this.Data.SaveChanges();

            return RedirectToAction("Index", new { id = picture.ContestId });
        }
Пример #8
0
 public PictureModel UpdatePicture(PictureInputModel pictureInputModel)
 {
     return(Post <PictureModel, PictureInputModel>("core_user_update_picture", pictureInputModel));
 }
 public ActionResult Create()
 {
     var model = new PictureInputModel();
     return this.View(model);
 }
Пример #10
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? this.Url.Content("~/");
            if (this.ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName    = this.Input.Username,
                    Email       = this.Input.Email,
                    PhoneNumber = this.Input.PhoneNumber,
                    UserType    = Enum.Parse <UserType>(this.Input.AccountType),
                };

                if (this.Input.ProfilePicture != null)
                {
                    var    pictureName = this.Input.Username + GlobalConstants.ProfilePicture;
                    string pictureLink = await this.cloudinaryService.UploadPictureAsync(this.Input.ProfilePicture, pictureName);

                    var picture = new PictureInputModel()
                    {
                        Link = pictureLink, Title = user.UserName, Description = user.UserName
                    };
                    var pictureToDb = await this.picureService.AddPictureToDb(picture, user);

                    bool isGenerate = await this.picureService.GenerateProfilePicture(picture, user);
                }

                if (user.UserType == UserType.User)
                {
                    user.FirstLogin = true;
                }

                var isRoot = !this.userManager.Users.Any();

                var result = await this.userManager.CreateAsync(user, this.Input.Password);

                if (result.Succeeded && user.UserType == UserType.User)
                {
                    if (isRoot)
                    {
                        await this.userManager.AddToRoleAsync(user, GlobalConstants.AdministratorRoleName);
                    }
                    else
                    {
                        await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName);
                    }


                    this.logger.LogInformation("User created a new account with password.");

                    var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = this.Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: this.Request.Scheme);

                    await this.emailSender.SendEmailAsync(
                        this.Input.Email,
                        "Confirm your email",
                        $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");


                    await this.signInManager.SignInAsync(user, isPersistent : false);

                    return(this.Redirect(GlobalConstants.HomeUrl));
                }

                if (user.UserType == UserType.Artist && result.Succeeded)
                {
                    if (user.UserType == UserType.Artist)
                    {
                        await this.userManager.AddToRoleAsync(user, GlobalConstants.ArtistRoleName);

                        await this.signInManager.SignInAsync(user, isPersistent : false);

                        return(this.RedirectToPage("./ArtistRegister"));
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(this.Page());
        }