コード例 #1
0
        public ActionResult AddPicture(AddPictureModel picture)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var pictureId = CreatePicture(picture);
                    var user      = userService.GetUserEntity(User.Identity.Name);

                    var profile = new PictureProfileBll()
                    {
                        Description = picture.Description,
                        LoadingDate = DateTime.Now,
                        PictureId   = pictureId,
                        UserId      = user.Id,
                    };
                    picProfileService.CreatePictureProfile(profile);

                    TempData["MessageType"]         = MessageType.success;
                    TempData["StrongResultMessage"] = "Фото успешно загружено";
                }
                catch (Exception)
                {
                    TempData["MessageType"]         = MessageType.info;
                    TempData["StrongResultMessage"] = "Не удалось загрузить новое фото";
                }
                return(RedirectToAction("ShowPhotoAlbum", "PhotoAlbum"));
            }
            return(View(picture));
        }
コード例 #2
0
        public void CreatePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
                throw new ArgumentNullException("profile");

            repository.Create(profile.ToDal());
            uow.Commit();
        }
コード例 #3
0
        public void CreatePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            repository.Create(profile.ToDal());
            uow.Commit();
        }
コード例 #4
0
        public void DeletePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
                throw new ArgumentNullException("profile");

            if (profile.Id <= 0)
                throw new InvalidIdException();
            
            var existedProfile = repository.GetById(profile.Id);
            if (existedProfile == null)
                throw new ArgumentException("The profile cannot be found");

            repository.Delete(existedProfile);
            uow.Commit();
        }
コード例 #5
0
        public void UpdatePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
                throw new ArgumentNullException("profile");

            PictureProfileDal currentPictureProfile = profile.ToDal();
            PictureProfileDal existedPictureProfile = repository.GetById(profile.Id);
            if (existedPictureProfile == null)
                throw new EntityNotFoundException("profile", profile.Id);

            existedPictureProfile.Description = currentPictureProfile.Description;
            existedPictureProfile.PictureId = currentPictureProfile.PictureId;
            existedPictureProfile.Rating = currentPictureProfile.Rating;

            repository.Update(existedPictureProfile);
            uow.Commit();

        }
コード例 #6
0
        public void UpdatePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            PictureProfileDal currentPictureProfile = profile.ToDal();
            PictureProfileDal existedPictureProfile = repository.GetById(profile.Id);

            if (existedPictureProfile == null)
            {
                throw new EntityNotFoundException("profile", profile.Id);
            }

            existedPictureProfile.Description = currentPictureProfile.Description;
            existedPictureProfile.PictureId   = currentPictureProfile.PictureId;
            existedPictureProfile.Rating      = currentPictureProfile.Rating;

            repository.Update(existedPictureProfile);
            uow.Commit();
        }
コード例 #7
0
        public void DeletePictureProfile(PictureProfileBll profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            if (profile.Id <= 0)
            {
                throw new InvalidIdException();
            }

            var existedProfile = repository.GetById(profile.Id);

            if (existedProfile == null)
            {
                throw new ArgumentException("The profile cannot be found");
            }

            repository.Delete(existedProfile);
            uow.Commit();
        }
コード例 #8
0
        private PictureProfileModel Map(PictureProfileBll profile, int index)
        {
            var modelProfile = new PictureProfileModel()
            {
                Description = profile.Description,
                LoadingDate = profile.LoadingDate,
                PictureId   = profile.PictureId,
                Index       = index,
                UserId      = profile.UserId,
            };

            PictureBll picture = pictureService.GetPictureById(profile.PictureId);

            if (picture == null)
            {
                return(null);
            }

            modelProfile.Name  = picture.Name;
            modelProfile.Image = Convert.ToBase64String(picture.Image);

            return(modelProfile);
        }
コード例 #9
0
ファイル: BllMapper.cs プロジェクト: tEkaterina/photoalbum
 public static PictureProfileDal ToDal(this PictureProfileBll profileBll)
 {
     return(Mapper.Map <PictureProfileBll, PictureProfileDal>(profileBll));
 }