예제 #1
0
 public async Task <int> SaveUser(DtoUser user)
 {
     try
     {
         using (var data = Context)
         {
             var p =
                 await
                     (from item in data.Users where user.Id == item.id select item).FirstOrDefaultAsync();
             // Updating
             if (p != null)
             {
                 p.login = user.Login;
                 p.email = user.Email;
                 if (user.Image != null)
                 {
                     p.image = Convert.FromBase64String(user.Image);
                 }
                 p.password = user.Password;
             }
             // Adding new
             else
             {
                 data.Users.Add(UserConverter.DtoToDataAccess(user));
             }
             await data.SaveChangesAsync();
         }
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
예제 #2
0
        public static DtoUser DataAccsessToDto(Users d)
        {
            var dto = new DtoUser
            {
                Id       = d.id,
                Email    = d.email,
                Login    = d.login,
                Password = d.password
            };

            if (d.image != null)
            {
                dto.Image = Convert.ToBase64String(d.image);
            }
            return(dto);
        }
예제 #3
0
        public static Users DtoToDataAccess(DtoUser c)
        {
            var user = new Users
            {
                id       = c.Id,
                password = c.Password,
                email    = c.Email,
                login    = c.Login
            };

            if (c.Image != null)
            {
                user.image = Convert.FromBase64String(c.Image);
            }
            return(user);
        }