public async Task Pic(ProfilePictureModel model)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = 500;
                return;
            }

            var imageProcessing = new ProfileGenerator();

            var nameParse = model.Name.Split(' ');
            var firstName = nameParse[0];
            var lastName  = string.Empty;

            if (nameParse.Length > 1)
            {
                lastName = nameParse[nameParse.Length - 1];
            }

            var pic = imageProcessing.GenerateProfile(
                firstName: firstName,
                lastName: lastName,
                width: model.Width,
                height: model.Height,
                color: model.Color
                );

            // Temporary
            var buffer = pic.GetBuffer();

            Response.ContentType = "image/jpeg";
            await Response.Body.WriteAsync(buffer, 0, buffer.Length);

            pic.Close();
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("PictureId,NameOfUser,imageName")] ProfilePictureModel profilePictureModel)
        {
            if (id != profilePictureModel.PictureId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(profilePictureModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfilePictureModelExists(profilePictureModel.PictureId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(profilePictureModel));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("PictureId,NameOfUser,ImageFile")] ProfilePictureModel profilePictureModel)
        {
            if (ModelState.IsValid)
            {
                //Saving image to wwwroot/image with filename and timestamp
                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(profilePictureModel.ImageFile.FileName);        //name of the file
                string extension   = Path.GetExtension(profilePictureModel.ImageFile.FileName);                       //example .jpg .png
                profilePictureModel.imageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; //combine name and filetype and date
                string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await profilePictureModel.ImageFile.CopyToAsync(fileStream);
                }

                _context.Add(profilePictureModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(profilePictureModel));
        }
        public ActionResult ProfilePicture(int customerId)
        {
            bool   avatarEnabled     = false;
            string avatarUrl         = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar);
            string fullSizeAvatarUrl = _pictureService.GetDefaultPictureUrl(0, PictureType.Avatar);
            var    isCurrentUser     = _workContext.CurrentCustomer.Id == customerId;

            if (_customerSettings.AllowCustomersToUploadAvatars)
            {
                avatarEnabled = true;
                var customer         = _customerService.GetCustomerById(customerId);
                var customerAvatarId = customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId);

                if (customerAvatarId != 0)
                {
                    avatarUrl         = _pictureService.GetPictureUrl(customerAvatarId, _mediaSettings.AvatarPictureSize);
                    fullSizeAvatarUrl = _pictureService.GetPictureUrl(customerAvatarId);
                }
                else
                {
                    if (!_customerSettings.DefaultAvatarEnabled)
                    {
                        avatarEnabled = false;
                    }
                }
            }


            var model = new ProfilePictureModel()
            {
                CanEdit           = isCurrentUser && _customerSettings.AllowCustomersToUploadAvatars,
                AvatarEnabled     = avatarEnabled,
                AvatarUrl         = avatarUrl,
                FullSizeAvatarUrl = fullSizeAvatarUrl
            };

            return(View(MobSocialConstant.ViewsPath + "/mobSocial/_ProfilePicture.cshtml", model));
        }
示例#5
0
        public ActionResult ChangeProfilePicture()
        {
            var tbl            = UserManager.FindById(User.Identity.GetUserId()).TblProfilePictures.ToList();
            var firstOrDefault = tbl.Where(item => item.IsProfile == true).Select(item => item.PicturePath).FirstOrDefault();


            var listUrls = tbl.Select(item => item.PicturePath).ToList();
            var model    = new ProfilePictureModel
            {
                ListUrls = listUrls
            };

            if (firstOrDefault != null)
            {
                var selectedPicture = firstOrDefault.ToString();

                listUrls.RemoveAt(listUrls.FindIndex(item => item == selectedPicture));
                listUrls.Insert(0, selectedPicture);
                model.SelectedPicture = selectedPicture;
                model.IsActiveProfile = true;
            }
            return(View(model));
        }