Ejemplo n.º 1
0
 public void Update(ProfileImageProperty profileImage)
 {
     _frapperDbContext.Entry(profileImage).State = EntityState.Modified;
 }
        public IActionResult Upload(string filename, IFormFile blob)
        {
            try
            {
                string systemFileExtenstion = filename.Substring(filename.LastIndexOf('.'));

                using (var image = Image.Load(blob.OpenReadStream()))
                {
                    var newfileName200 = GenerateFileName("Photo_200_200_", systemFileExtenstion);
                    var filepath200    = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ProfileImages")).Root + $@"\{newfileName200}";
                    image.Mutate(x => x.Resize(200, 200));
                    image.Save(filepath200);

                    image.Mutate(x => x.Resize(180, 180));
                    var newfileName180 = GenerateFileName("Photo_180_180_", systemFileExtenstion);
                    var filepath180    = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ProfileImages")).Root + $@"\{newfileName180}";
                    image.Save(filepath180);

                    var newfileName32 = GenerateFileName("Photo_32_32_", systemFileExtenstion);
                    var filepath32    = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ProfileImages")).Root + $@"\{newfileName32}";
                    image.Mutate(x => x.Resize(32, 32));
                    image.Save(filepath32);

                    if (_profileImageQueries.CheckProfileImageExists(Convert.ToInt64(HttpContext.Session.GetString(AllSessionKeys.UserId))))
                    {
                        var getprofileImage =
                            _profileImageQueries.GetProfileImageByProfileImageId(
                                Convert.ToInt64(HttpContext.Session.GetString(AllSessionKeys.UserId)));

                        if (getprofileImage != null)
                        {
                            getprofileImage.ImageName  = "ProfileImage";
                            getprofileImage.ImageType  = systemFileExtenstion;
                            getprofileImage.ModifiedOn = DateTime.Now;
                            getprofileImage.Tiny       = $"/ProfileImages/{newfileName32}";
                            getprofileImage.Small      = $"/ProfileImages/{newfileName180}";
                            getprofileImage.Medium     = $"/ProfileImages/{newfileName200}";
                            getprofileImage.Status     = true;
                            getprofileImage.ModifiedBy =
                                Convert.ToInt64(HttpContext.Session.GetString(AllSessionKeys.UserId));


                            _unitOfWorkEntityFramework.ProfileImageCommand.Update(getprofileImage);
                            _unitOfWorkEntityFramework.Commit();
                        }
                    }
                    else
                    {
                        ProfileImageProperty profileImageProperty = new ProfileImageProperty()
                        {
                            ProfileImageId = 0,
                            ImageName      = "ProfileImage",
                            ImageType      = systemFileExtenstion,
                            CreatedOn      = DateTime.Now,
                            Tiny           = $"/ProfileImages/{newfileName32}",
                            Small          = $"/ProfileImages/{newfileName180}",
                            Medium         = $"/ProfileImages/{newfileName200}",
                            Status         = true,
                            CreatedBy      = Convert.ToInt64(HttpContext.Session.GetString(AllSessionKeys.UserId))
                        };

                        _unitOfWorkEntityFramework.ProfileImageCommand.Add(profileImageProperty);
                        _unitOfWorkEntityFramework.Commit();
                    }
                }

                _notificationService.SuccessNotification("Message", "Your Profile Photo Update Successfully!");

                return(Json(new { Message = "OK" }));
            }
            catch (Exception)
            {
                return(Json(new { Message = "ERROR" }));
            }
        }
Ejemplo n.º 3
0
 public void Add(ProfileImageProperty profileImage)
 {
     _frapperDbContext.ProfileImagePropertys.Add(profileImage);
 }