Ejemplo n.º 1
0
        public List<TripTO> GetAllTrips(UserTO userTO)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid = new Guid(userTO.token);
                var query = (from trip in db.Trips
                             join user in db.Users
                             on   trip.userId.Value
                             equals user.id
                             where user.token == guid
                             select trip);

                List<TripTO> trips = new List<TripTO>();

                foreach (var t in query)
                {
                    TripTO trip = new TripTO();
                    trip.id = t.id;
                    trip.name = t.name;
                    trip.notes = t.notes;
                    if (t.startDate != null)
                        trip.startDate = ((DateTime)t.startDate).ToString("yyyy-MM-dd");
                    if (t.endDate != null)
                        trip.endDate = ((DateTime)t.endDate).ToString("yyyy-MM-dd");
                    trips.Add(trip);
                }

                return trips;
            }
        }
Ejemplo n.º 2
0
        public List <TripTO> GetAllTrips(UserTO userTO)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid  = new Guid(userTO.token);
                var query = (from trip in db.Trips
                             join user in db.Users
                             on trip.userId.Value
                             equals user.id
                             where user.token == guid
                             select trip);

                List <TripTO> trips = new List <TripTO>();

                foreach (var t in query)
                {
                    TripTO trip = new TripTO();
                    trip.id    = t.id;
                    trip.name  = t.name;
                    trip.notes = t.notes;
                    if (t.startDate != null)
                    {
                        trip.startDate = ((DateTime)t.startDate).ToString("yyyy-MM-dd");
                    }
                    if (t.endDate != null)
                    {
                        trip.endDate = ((DateTime)t.endDate).ToString("yyyy-MM-dd");
                    }
                    trips.Add(trip);
                }

                return(trips);
            }
        }
Ejemplo n.º 3
0
        public string ValidateUser(UserTO user)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var users = (from t in db.Users
                             where t.username == user.username &&
                             t.password == user.password
                             select t).FirstOrDefault();

                if (users == null)
                {
                    return("unknown user");
                }

                if (users.token != null)
                {
                    user.token = users.token.ToString();
                }
                else
                {
                    user.token = null;
                }

                user.id = users.id;
            }
            return("user validated");
        }
Ejemplo n.º 4
0
 public string CreateUser(UserTO user)
 {
     using (var db = new Fish360Project.f360Entities())
     {
         Users newUser = new Users();
         newUser.username = user.username;
         newUser.password = user.password;
         db.Users.Add(newUser);
         db.SaveChanges();
     }
     return "success";
 }
Ejemplo n.º 5
0
 public string CreateUser(UserTO user)
 {
     using (var db = new Fish360Project.f360Entities())
     {
         Users newUser = new Users();
         newUser.username = user.username;
         newUser.password = user.password;
         db.Users.Add(newUser);
         db.SaveChanges();
     }
     return("success");
 }
Ejemplo n.º 6
0
        public void Register([FromBody] UserTO userTO)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                Users newUser = new Users();
                newUser.username = userTO.username;
                newUser.password = userTO.password;
                newUser.token    = Guid.NewGuid();

                db.Users.Add(newUser);
                db.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public string CreateTrip(TripTO tripTO, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                UserTO userTO = FindUserForToken(token);

                Trips newTrip = new Trips();
                newTrip.name      = tripTO.name;
                newTrip.notes     = tripTO.notes;
                newTrip.startDate = DateTime.ParseExact(tripTO.startDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                newTrip.endDate   = DateTime.ParseExact(tripTO.endDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                newTrip.userId    = userTO.id;

                db.Trips.Add(newTrip);
                db.SaveChanges();
            }
            return(null);
        }
Ejemplo n.º 8
0
 public UserTO FindUserForToken(string token)
 {
     using (var db = new Fish360Project.f360Entities())
     {
         Guid guid = new Guid(token);
         var users = (from u in db.Users
                      where u.token == guid
                      select u).FirstOrDefault();
         if (users != null)
         {
             UserTO user = new UserTO();
             user.username = users.username;
             user.password = users.password;
             user.id = users.id;
             user.token = users.token.ToString();
             return user;
         }
     }
     return null;
 }
Ejemplo n.º 9
0
 public UserTO FindUserForToken(string token)
 {
     using (var db = new Fish360Project.f360Entities())
     {
         Guid guid  = new Guid(token);
         var  users = (from u in db.Users
                       where u.token == guid
                       select u).FirstOrDefault();
         if (users != null)
         {
             UserTO user = new UserTO();
             user.username = users.username;
             user.password = users.password;
             user.id       = users.id;
             user.token    = users.token.ToString();
             return(user);
         }
     }
     return(null);
 }
Ejemplo n.º 10
0
        public string ValidateUser(UserTO user)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var users = (from t in db.Users
                             where t.username == user.username
                             && t.password == user.password
                             select t).FirstOrDefault();

                if (users == null)
                    return "unknown user";

                if (users.token != null)
                    user.token = users.token.ToString();
                else
                    user.token = null;

                user.id = users.id;
            }
            return "user validated";
        }
Ejemplo n.º 11
0
        public string ValidateUsername(UserTO user)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var users = (from t in db.Users
                             where t.username == user.username
                             select t).FirstOrDefault();
                if (users == null)
                {
                    return("username does not exist");
                }
                user.id    = users.id;
                user.token = users.token.ToString();

                if (users == null)
                {
                    return("username does not exist");
                }
            }
            return("username exists");
        }
Ejemplo n.º 12
0
        public UserTO Login(string username, string password)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var usr = (from user in db.Users
                           where user.username == username
                           && user.password == password
                           select user).FirstOrDefault();

                if (usr == null)
                    return null;

                UserTO newUserTO = new UserTO();
                newUserTO.id = usr.id;
                newUserTO.username = usr.username;
                newUserTO.password = usr.password;
                newUserTO.token = usr.token.ToString();

                return newUserTO;
            }
        }
Ejemplo n.º 13
0
        public UserTO Login(string username, string password)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var usr = (from user in db.Users
                           where user.username == username &&
                           user.password == password
                           select user).FirstOrDefault();

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

                UserTO newUserTO = new UserTO();
                newUserTO.id       = usr.id;
                newUserTO.username = usr.username;
                newUserTO.password = usr.password;
                newUserTO.token    = usr.token.ToString();

                return(newUserTO);
            }
        }
Ejemplo n.º 14
0
        public string LoginUser(UserTO user)
        {
            string validation = ValidateUser(user);
            Guid guid;
            if (validation == "user validated")
            {
                using (var db = new Fish360Project.f360Entities())
                {
                    var users = (from t in db.Users
                                 where t.username == user.username
                                 && t.password == user.password
                                 select t).FirstOrDefault();

                    guid = Guid.NewGuid();

                    users.token = guid;

                    db.SaveChanges();
                }
                return guid.ToString();
            }
            return "unable to login";
        }
Ejemplo n.º 15
0
        public string LoginUser(UserTO user)
        {
            string validation = ValidateUser(user);
            Guid   guid;

            if (validation == "user validated")
            {
                using (var db = new Fish360Project.f360Entities())
                {
                    var users = (from t in db.Users
                                 where t.username == user.username &&
                                 t.password == user.password
                                 select t).FirstOrDefault();

                    guid = Guid.NewGuid();

                    users.token = guid;

                    db.SaveChanges();
                }
                return(guid.ToString());
            }
            return("unable to login");
        }
Ejemplo n.º 16
0
        public string ValidateUsername(UserTO user)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var users = (from t in db.Users
                             where t.username == user.username
                             select t).FirstOrDefault();
                if (users == null)
                    return "username does not exist";
                user.id = users.id;
                user.token = users.token.ToString();

                if (users == null)
                    return "username does not exist";
            }
            return "username exists";
        }