public HttpResponseMessage EditUserImage(int id)
        {
            try
            {
                using (logic)
                {
                    string fileName = Guid.NewGuid() + ".jpg";
                    string fullPath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName);


                    using (FileStream stream = new FileStream(fullPath, FileMode.Create))
                    {
                        HttpContext.Current.Request.InputStream.CopyTo(stream); // This will save the file
                    }

                    UsersDTO updatedUser = logic.EditPicture(id, fileName);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
예제 #2
0
        public UsersDTO EditPassword(UsersDTO user)
        {
            User userToUpdate = DB.Users.Where(p => p.UserID == user.id).SingleOrDefault();

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

            userToUpdate.Password = user.password;

            DB.SaveChanges();
            return(user);
        }
 public HttpResponseMessage AddUser(UsersDTO user)
 {
     try
     {
         using (logic)
         {
             UsersDTO addedUser = logic.AddUser(user);
             return(Request.CreateResponse(HttpStatusCode.Created, addedUser));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
예제 #4
0
        public UsersDTO AddUser(UsersDTO user)
        {
            User userToAdd = new User
            {
                FirstName    = user.firstName,
                LastName     = user.lastName,
                SocialNumber = user.socialNumber,
                UserName     = user.userName,
                DateOfBirth  = user.dateOfBirth,
                GenderID     = (byte)user.gender.id,
                Email        = user.email,
                Image        = user.image,
                RankID       = user.rank.id,
                Password     = FormsAuthentication.HashPasswordForStoringInConfigFile(user.password, "md5")
            };

            DB.Users.Add(userToAdd);
            DB.SaveChanges();
            user.id = userToAdd.UserID;
            return(user);
        }
예제 #5
0
        public UsersDTO EditPicture(int id, string imageCode)
        {
            User userToUpdate = DB.Users.Where(p => p.UserID == id).SingleOrDefault();

            if (userToUpdate == null)
            {
                return(null);
            }
            if (userToUpdate.Image != imageCode && userToUpdate.Image != null)
            {
                File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/" + userToUpdate.Image));
            }


            userToUpdate.Image = imageCode;

            DB.SaveChanges();
            UsersDTO userToReturn = new UsersDTO
            {
                id           = userToUpdate.UserID,
                userName     = userToUpdate.UserName,
                firstName    = userToUpdate.FirstName,
                lastName     = userToUpdate.LastName,
                socialNumber = userToUpdate.SocialNumber,
                email        = userToUpdate.Email,
                password     = userToUpdate.Password,
                image        = userToUpdate.Image,
                dateOfBirth  = userToUpdate.DateOfBirth,
                gender       = new UserGenderDTO
                {
                    id     = userToUpdate.Gender.GenderID,
                    gender = userToUpdate.Gender.Gender1
                },
                rank = new UserRankDTO {
                    id = userToUpdate.Rank.RankID, rank = userToUpdate.Rank.Rank1
                }
            };

            return(userToReturn);
        }
        public HttpResponseMessage DeleteUserImage(int id)
        {
            try
            {
                using (logic)
                {
                    UsersDTO updatedUser = logic.EditPicture(id, null);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
예제 #7
0
        public UsersDTO UpdateUser(UsersDTO user)
        {
            User userToUpdate = DB.Users.Where(p => p.UserID == user.id).SingleOrDefault();

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

            userToUpdate.UserID       = user.id;
            userToUpdate.FirstName    = user.firstName;
            userToUpdate.LastName     = user.lastName;
            userToUpdate.SocialNumber = user.socialNumber;
            userToUpdate.UserName     = user.userName;
            userToUpdate.DateOfBirth  = user.dateOfBirth;
            userToUpdate.GenderID     = (byte)user.gender.id;
            userToUpdate.Email        = user.email;
            userToUpdate.Image        = user.image;
            userToUpdate.RankID       = user.rank.id;

            DB.SaveChanges();
            return(user);
        }
        public HttpResponseMessage EditPassword(int id, UsersDTO user)
        {
            try
            {
                using (logic)
                {
                    user.id = id;

                    UsersDTO updatedUser = logic.EditPassword(user);

                    if (updatedUser == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }