/// <summary>
        /// Updates the user photo.
        /// </summary>
        /// <param name="userPhoto">The user photo.</param>
        /// <returns></returns>
        public Response <UserPhotoModel> UpdateUserPhoto(UserPhotoModel userPhoto)
        {
            var spParameters = BuildUserPhotoSpParams(userPhoto, true);
            var repository   = _unitOfWork.GetRepository <UserPhotoModel>();

            return(_unitOfWork.EnsureInTransaction(repository.ExecuteNQStoredProc, "usp_UpdateUserPhoto", spParameters,
                                                   forceRollback: userPhoto.ForceRollback.GetValueOrDefault(false)));
        }
示例#2
0
        public ActionResult Delete(UserPhotoModel photo)
        {
            var photoModel = _photoService.GetPhoto(photo.Id);

            _photoService.RemovePhoto(new UserPhotoBLL()
            {
                Id = photo.Id,
            });
            System.IO.File.Delete(Server.MapPath(photoModel.PhotoAddress));
            return(RedirectToAction("Photos"));
        }
示例#3
0
        public ActionResult HomePage(User user)
        {
            UserPhotoModel model    = new UserPhotoModel();
            AccountService service  = new AccountService();
            LoginResponse  response = service.Login(user.Name, user.Password);

            model.User       = response.User;
            Session["model"] = model;
            if (response.Code == (int)Constants.ERROR_ENUMS.SUCCESS)
            {
                return(RedirectToAction("PhotoPage", "Galery"));
            }
            return(View(model));
        }
        /// <summary>
        /// Builds the user photo sp parameters.
        /// </summary>
        /// <param name="userPhoto">The user photo.</param>
        /// <param name="isUpdate">if set to <c>true</c> [is update].</param>
        /// <returns></returns>
        private List <SqlParameter> BuildUserPhotoSpParams(UserPhotoModel userPhoto, bool isUpdate)
        {
            var spParameters = new List <SqlParameter>();

            if (isUpdate)
            {
                spParameters.Add(new SqlParameter("UserPhotoID", userPhoto.UserPhotoID));
            }

            spParameters.Add(new SqlParameter("UserID", (object)userPhoto.UserID ?? DBNull.Value));
            spParameters.Add(new SqlParameter("PhotoID", (object)userPhoto.PhotoID ?? DBNull.Value));
            spParameters.Add(new SqlParameter("IsPrimary", (object)userPhoto.IsPrimary ?? DBNull.Value));
            spParameters.Add(new SqlParameter("ModifiedOn", userPhoto.ModifiedOn ?? DateTime.Now));

            return(spParameters);
        }
示例#5
0
 public ActionResult OnAvatar(UserPhotoModel photo)
 {
     try
     {
         _photoService.EditPhoto(new UserPhotoBLL()
         {
             Id       = photo.Id,
             IsAvatar = true
         });
         return(RedirectToAction("Photos"));
     }
     catch
     {
         return(View());
     }
 }
示例#6
0
        // GET: Galery

        public ActionResult PhotoPage(int?page)
        {
            PhotoService photoService = new PhotoService();

            UserPhotoModel model = (UserPhotoModel)Session["model"];

            if (page == null)
            {
                PhotoResponse photoResponse = photoService.GetPhotos(model.User);
                model.Photos = photoResponse.Photos;
            }
            else
            {
                PhotoResponse photoResponse = photoService.GetPhotosPartByPart(model.User, (int)page);
                model.Photos = photoResponse.Photos;
            }
            return(View(model));
        }
示例#7
0
 public ActionResult Edit(UserPhotoModel photo)
 {
     try
     {
         if (!string.IsNullOrEmpty(photo.Description))
         {
             _photoService.EditPhoto(new UserPhotoBLL()
             {
                 Id          = photo.Id,
                 Description = photo.Description
             });
         }
         return(RedirectToAction("Photos", new { id = User.Identity.GetUserId() }));
     }
     catch
     {
         return(View());
     }
 }
        public void AddUserPhoto_Failed()
        {
            // Arrange
            var url = baseRoute + "addUserPhoto";

            var userPhoto = new UserPhotoModel
            {
                UserID        = -1,
                IsPrimary     = true,
                PhotoID       = 1,
                ForceRollback = true
            };

            // Act
            var response = communicationManager.Post <UserPhotoModel, Response <UserPhotoModel> >(userPhoto, url);

            // Assert
            Assert.IsTrue(response != null, "Response can't be null");
            Assert.IsTrue(response.ResultCode != 0, "User photo is created for invalid data.");
        }
        public void UpdateUserPhoto_Success()
        {
            // Arrange
            var url = baseRoute + "updateUserPhoto";

            var userPhoto = new UserPhotoModel
            {
                UserPhotoID   = 1,
                UserID        = 5,
                IsPrimary     = false,
                PhotoID       = 1,
                ForceRollback = true
            };

            // Act
            var response = communicationManager.Put <UserPhotoModel, Response <UserPhotoModel> >(userPhoto, url);

            // Assert
            Assert.IsTrue(response != null, "Response can't be null");
            Assert.IsTrue(response.ResultCode == 0, "User photo could not be updated.");
        }
        public void UpdateUserPhoto_Failed()
        {
            // Arrange
            var url = baseRoute + "updateUserPhoto";

            var userPhoto = new UserPhotoModel
            {
                UserPhotoID   = -1,
                UserID        = -1,
                IsPrimary     = false,
                PhotoID       = 1,
                ForceRollback = true
            };

            // Act
            var response = communicationManager.Put <UserPhotoModel, Response <UserPhotoModel> >(userPhoto, url);

            // Assert
            Assert.IsTrue(response != null, "Response can't be null");
            Assert.IsTrue(response.RowAffected == 0, "User photo is updated for invalid data.");
        }
示例#11
0
        /// <summary>
        /// To the view model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static UserPhotoViewModel ToViewModel(this UserPhotoModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new UserPhotoViewModel
            {
                UserPhotoID   = entity.UserPhotoID,
                UserID        = entity.UserID,
                PhotoID       = entity.PhotoID,
                PhotoBLOB     = entity.PhotoBLOB,
                ThumbnailBLOB = entity.ThumbnailBLOB,
                IsPrimary     = entity.IsPrimary,
                ModifiedOn    = entity.ModifiedOn,
                ForceRollback = entity.ForceRollback
            };

            return(model);
        }
示例#12
0
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static UserPhotoModel ToModel(this UserPhotoViewModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new UserPhotoModel
            {
                UserPhotoID   = model.UserPhotoID,
                UserID        = model.UserID,
                PhotoID       = model.PhotoID,
                PhotoBLOB     = model.PhotoBLOB,
                ThumbnailBLOB = model.ThumbnailBLOB,
                IsPrimary     = model.IsPrimary,
                ModifiedOn    = model.ModifiedOn,
                ForceRollback = model.ForceRollback
            };

            return(entity);
        }
示例#13
0
        public ActionResult Create(HttpPostedFileBase upload, UserPhotoModel model)
        {
            if (upload != null)
            {
                if (IsImage(upload))
                {
                    //string fileName = System.IO.Path.GetFileName(upload.FileName);
                    Directory.CreateDirectory(Server.MapPath("/Content/UserPhotos/" + User.Identity.GetUserId() + "/"));
                    string address = Server.MapPath("/Content/UserPhotos/" + User.Identity.GetUserId() + "/" + Guid.NewGuid().ToString() + "." + upload.FileName.Substring(upload.FileName.LastIndexOf(".") + 1));
                    upload.SaveAs(address);

                    _photoService.AddPhoto(new UserPhotoBLL()
                    {
                        PhotoAddress = @"\" + address.Replace(Request.PhysicalApplicationPath, String.Empty),
                        UserId       = User.Identity.GetUserId(),
                        Description  = model.Description
                    });
                    return(RedirectToAction("Photos"));
                }
            }
            return(View());
        }
示例#14
0
 public IHttpActionResult AddMyProfilePhoto(UserPhotoModel userPhoto)
 {
     return(new HttpResult <Response <UserPhotoModel> >(userPhotoRuleEngine.AddUserPhoto(userPhoto), Request));
 }
示例#15
0
        /// <summary>
        /// Updates the user photo.
        /// </summary>
        /// <param name="userPhoto">The user photo.</param>
        /// <returns></returns>
        public Response <UserPhotoModel> UpdateUserPhoto(UserPhotoModel userPhoto)
        {
            const string apiUrl = BaseRoute + "UpdateUserPhoto";

            return(communicationManager.Put <UserPhotoModel, Response <UserPhotoModel> >(userPhoto, apiUrl));
        }
 /// <summary>
 /// Adds the user photo.
 /// </summary>
 /// <param name="userPhoto">The user photo.</param>
 /// <returns></returns>
 public Response <UserPhotoModel> AddUserPhoto(UserPhotoModel userPhoto)
 {
     return(userPhotoService.AddUserPhoto(userPhoto));
 }
 /// <summary>
 /// Updates the user photo.
 /// </summary>
 /// <param name="userPhoto">The user photo.</param>
 /// <returns></returns>
 public Response <UserPhotoModel> UpdateUserPhoto(UserPhotoModel userPhoto)
 {
     return(userPhotoService.UpdateUserPhoto(userPhoto));
 }
示例#18
0
 public IHttpActionResult UpdateUserPhoto(UserPhotoModel userPhoto)
 {
     return(new HttpResult <Response <UserPhotoModel> >(userPhotoRuleEngine.UpdateUserPhoto(userPhoto), Request));
 }
示例#19
0
 public IHttpActionResult UpdateUserPhoto(UserPhotoModel userPhoto)
 {
     return(new HttpResult <Response <UserPhotoModel> >(userPhotoDataProvider.UpdateUserPhoto(userPhoto), Request));
 }