コード例 #1
0
ファイル: UsersController.cs プロジェクト: bilek993/parkUS
        public bool Put([FromBody] UserItem userNew)
        {
            using (var database = new DatabaseMainEntities())
            {
                if (UserDetailsVeryfication.CheckForEmptValues(userNew) ||
                    UserDetailsVeryfication.CheckUserExistance(userNew))
                {
                    return(false);
                }

                string hashedPassword = Sha256Hashing.Hash(userNew.Password);
                var    user           = new User
                {
                    Username = userNew.Username,
                    Password = hashedPassword,
                    Name     = userNew.Name,
                    Surname  = userNew.Surname,
                    Points   = Points.STARTING_POINTS
                };

                database.User.Add(user);
                database.SaveChanges();
            }

            return(true);
        }
コード例 #2
0
ファイル: PointsController.cs プロジェクト: bilek993/parkUS
 public int Get()
 {
     using (var database = new DatabaseMainEntities())
     {
         string username = Thread.CurrentPrincipal.Identity.Name;
         User   user     = database.User.FirstOrDefault(u => u.Username == username);
         return(user.Points ?? 0);
     }
 }
コード例 #3
0
        public static bool CheckUserExistance(UserItem user)
        {
            string username = user.Username;

            using (var database = new DatabaseMainEntities())
            {
                return(database.User.Any(u => u.Username == username));
            }
        }
コード例 #4
0
        public static bool VerifyCredentials(string username, string password)
        {
            string passwordHashed = Sha256Hashing.Hash(password);

            using (var database = new DatabaseMainEntities())
            {
                return(database.User.Any(u => u.Username == username &&
                                         u.Password == passwordHashed));
            }
        }
コード例 #5
0
ファイル: PointsController.cs プロジェクト: bilek993/parkUS
        public void Post([FromBody] int parkingPointId)
        {
            using (var database = new DatabaseMainEntities())
            {
                string username = Thread.CurrentPrincipal.Identity.Name;
                database.User.FirstOrDefault(u => u.Username == username).Points -= 10;
                database.ParkingPoints.FirstOrDefault(pp => pp.Id == parkingPointId).User.Points += 9;

                ParkingPoints point = database.ParkingPoints.FirstOrDefault(pp => pp.Id == parkingPointId);
                database.ParkingPoints.Remove(point);
                database.SaveChanges();
            }
        }
コード例 #6
0
 public List <ParkingPointItem> Get()
 {
     using (var database = new DatabaseMainEntities())
     {
         string username = Thread.CurrentPrincipal.Identity.Name;
         return(database.ParkingPoints
                .Where(us => us.User.Username != username)
                .Select(pp => new ParkingPointItem
         {
             Id = pp.Id,
             Creator = pp.User.Name + " " + pp.User.Surname,
             Longitude = pp.Longitude,
             Latitude = pp.Latitude,
             Photo = pp.Photo,
             CreatedOn = pp.CreatedOn
         }).ToList());
     }
 }
コード例 #7
0
        public void Put([FromBody] ParkingPointItem parkingPointItemNew)
        {
            using (var database = new DatabaseMainEntities())
            {
                DateTime currentDate = DateTime.Now;

                string username = Thread.CurrentPrincipal.Identity.Name;
                User   user     = database.User.FirstOrDefault(u => u.Username == username);
                user.Points += 1;

                var parkingPoint = new ParkingPoints
                {
                    Longitude = parkingPointItemNew.Longitude,
                    Latitude  = parkingPointItemNew.Latitude,
                    Photo     = parkingPointItemNew.Photo,
                    CreatedOn = currentDate,
                    User      = user
                };

                database.ParkingPoints.Add(parkingPoint);
                database.SaveChanges();
            }
        }