public HttpResponseMessage PostMusterija([FromBody] Komentar kom)
        {
            HttpResponseMessage msg  = new HttpResponseMessage();
            KomentarRepository  repo = new KomentarRepository();

            try
            {
                using (var db = new SystemDBContext())
                {
                    kom.PostingTime = DateTime.Now;
                    kom.Id          = repo.GetKomentari().Count + 1;

                    db.Komentari.Add(kom);
                    db.SaveChanges();

                    msg = Request.CreateResponse(HttpStatusCode.Created, kom);
                    msg.Headers.Location = new Uri(Request.RequestUri + kom.Id.ToString());

                    return(msg);
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
        public HttpResponseMessage PutMusterijaKomentarisala(Musterija m) //kada komentarise, stavim da ej true
        {
            HttpResponseMessage msg = new HttpResponseMessage();

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Musterija must = db.Musterije.FirstOrDefault(x => x.Username == m.Username);

                    if (must != null)
                    {
                        must.Commented = true;
                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.OK, must);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Customer is not registered.");
                    }
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Error - {e.Message}");
            }

            return(msg);
        }
        public void DeleteUser(UserToken userToken)
        {
            using (var db = new SystemDBContext())
            {
                var user = db.Users.FirstOrDefault(x => x.HashId == userToken.UserId);
                if (user == null)
                {
                    throw HttpResponseExceptionHelper.Create("Identifiant d'usager invalide", HttpStatusCode.BadRequest);
                }

                db.Users.Remove(user);
                db.SaveChanges();
            }

            // delete all users friends
            var friendService = new FriendService(userToken);

            friendService.DeleteAllFriends();

            // delete profile
            var profileService = new ProfileService(userToken);

            profileService.DeleteMyProfile();

            // Delete daylies
            var dailyService = new DailyService(userToken);

            dailyService.DeleteAllDaily();
        }
Esempio n. 4
0
        public HttpResponseMessage PutChangeFinalLocation(Vozac vozac)
        {
            HttpResponseMessage msg = new HttpResponseMessage();

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Vozac v = db.Vozaci.FirstOrDefault(x => x.Username == vozac.Username);

                    if (vozac != null)
                    {
                        v.LocationID = vozac.LocationID;

                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.NoContent);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "There was internal error, drive is deleted.");
                    }
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while finishing");
            }

            return(msg);
        }
        /// <summary>
        /// Delete the specified map
        /// </summary>
        /// <param name="mapHashId"></param>
        public void DeleteMap(string mapHashId)
        {
            if (string.IsNullOrWhiteSpace(mapHashId))
            {
                throw HttpResponseExceptionHelper.Create("Invalid map hash id provided", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                var map = db.Maps.FirstOrDefault(x => x.HashId == mapHashId && x.CreatorhashId == UserToken.UserId);
                if (map == null)
                {
                    throw HttpResponseExceptionHelper.Create("No zone correspond to given hash id",
                                                             HttpStatusCode.BadRequest);
                }

                db.Maps.Remove(map);
                db.SaveChanges();

                var leaderboard = db.Leaderboards.FirstOrDefault(x => x.ZoneHashId == mapHashId);
                if (leaderboard != null)
                {
                    db.Leaderboards.Remove(leaderboard);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 6
0
        public HttpResponseMessage PutLocation([FromBody] JToken token) //klasa da mozes da iscitavas prosledjene primitivne tipove
        {
            HttpResponseMessage msg = new HttpResponseMessage();

            var id      = token.Value <int>("id");
            var address = token.Value <string>("address");

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Lokacija lk = db.Lokacije.FirstOrDefault(x => x.LocationId == id);

                    lk.Address.FullAddress = address;

                    db.SaveChanges();

                    msg = Request.CreateResponse(HttpStatusCode.OK, lk);
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while updating");
            }

            return(msg);
        }
        private DailyModel GetTodayDaily()
        {
            using (var db = new SystemDBContext())
            {
                var today    = DateTime.Today;
                var tomorrow = today.AddDays(1).AddHours(-1);

                var daily =
                    db.Daylies.FirstOrDefault(
                        x => x.UserHashId == UserToken.UserId && x.BeginTime >= today && x.EndTime <= tomorrow);

                if (daily == null)
                {
                    daily = new DailyModel()
                    {
                        BeginTime  = today,
                        EndTime    = tomorrow,
                        IsDone     = false,
                        UserHashId = UserToken.UserId,
                        DailyType  = DailyModelHelper.GetDailyType(today)
                    };

                    db.Daylies.Add(daily);
                    db.SaveChanges();
                }
                return(daily);
            }
        }
        public void RemoveFriend(string HashId, string Username)
        {
            if (HashId.IsNullOrWhiteSpace() || Username.IsNullOrWhiteSpace())
            {
                throw HttpResponseExceptionHelper.Create("Null friend name or id specified", HttpStatusCode.BadRequest);
            }

            if (UserToken == null)
            {
                throw HttpResponseExceptionHelper.Create("User token not specified", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                var toremove = db.Friends.FirstOrDefault(x => x.Player1HashId == UserToken.UserId &&
                                                         x.Player1Username == UserToken.Username &&
                                                         x.Player2HashId == HashId &&
                                                         x.Player2Username == Username);
                if (toremove == null)
                {
                    toremove = db.Friends.FirstOrDefault(x => x.Player1HashId == HashId &&
                                                         x.Player1Username == Username &&
                                                         x.Player2HashId == UserToken.UserId &&
                                                         x.Player2Username == UserToken.Username);
                }
                if (toremove != null)
                {
                    db.Friends.Remove(toremove);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 9
0
        public HttpResponseMessage PutIdForComm(JToken token)
        {
            HttpResponseMessage msg = new HttpResponseMessage();

            var komId = token.Value <int>("komId");
            var vozId = token.Value <int>("id");

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    //Komentar k = db.Komentari.FirstOrDefault(x => x.Id == komId);
                    Voznja v = db.Voznje.FirstOrDefault(x => x.Id == vozId);

                    if (v != null)
                    {
                        v.CommentID = komId;

                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.NoContent);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "There was internal error, drive is deleted.");
                    }
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while finishing");
            }

            return(msg);
        }
        /// <summary>
        /// Update map information
        /// </summary>
        /// <param name="mapModel"></param>
        /// <returns></returns>
        public void UpdateMap(MapModel mapModel)
        {
            if (string.IsNullOrWhiteSpace(mapModel.HashId))
            {
                throw HttpResponseExceptionHelper.Create("No map hash id specified", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                var map = db.Maps.FirstOrDefault(x => x.HashId == mapModel.HashId);

                if (map == null)
                {
                    throw HttpResponseExceptionHelper.Create("No map correspond to the given hashId",
                                                             HttpStatusCode.BadRequest);
                }

                // Update info
                if (!string.IsNullOrWhiteSpace(mapModel.Content))
                {
                    map.Content = mapModel.Content;
                }
                map.Level = mapModel.Level;

                map.UpdateTime = TimeHelper.CurrentCanadaTime();

                // Mark entity as modified
                db.Entry(map).State = System.Data.Entity.EntityState.Modified;
                // call SaveChanges
                db.SaveChanges();
            }
        }
        public List <BasicUserInfo> GetAllPublicProfile()
        {
            using (var db = new SystemDBContext())
            {
                // get all public profiles
                var profiles    = db.Profiles.Where(x => x.IsPrivate == false).ToList();
                var visibleUser = new List <BasicUserInfo>();

                // get all friends
                var friendService = new FriendService(UserToken);
                visibleUser.AddRange(friendService.GetAllFriends());

                foreach (var profile in profiles)
                {
                    // not contained in visible user yet ( not friends )
                    if (visibleUser.FirstOrDefault(x => x.HashId == profile.UserHashId) == null)
                    {
                        // search for user and add info if exist
                        var user = db.Users.FirstOrDefault(x => x.HashId == profile.UserHashId);
                        if (user != null)
                        {
                            visibleUser.Add(new BasicUserInfo()
                            {
                                AreFriend = false,
                                HashId    = user.HashId,
                                Username  = user.Username
                            });
                        }
                    }
                }
                return(visibleUser);
            }
        }
        public void AddLeaderEntry(string zoneHashId, LeaderModel leader)
        {
            if (string.IsNullOrWhiteSpace(zoneHashId))
            {
                throw HttpResponseExceptionHelper.Create("Empty map hash id specified", HttpStatusCode.BadRequest);
            }

            if (!LeaderModelHelper.IsValid(leader))
            {
                throw HttpResponseExceptionHelper.Create("Invalid leader entry specified", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                var leaderboard = db.Leaderboards.FirstOrDefault(x => x.ZoneHashId == zoneHashId);

                if (leaderboard == null)
                {
                    throw HttpResponseExceptionHelper.Create("Invalid map hash id provided. No related map.",
                                                             HttpStatusCode.BadRequest);
                }

                leaderboard.Leaders = GetLeaderString(InsertLeader(leaderboard, leader));
                db.SaveChanges();
            }
        }
 public void SendMessage(NodeVoteResponse vote)
 {
     if (vote.Status)
     {
         using (var db = new SystemDBContext())
         {
             try
             {
                 var user = db.IdvnAccounts.FirstOrDefault(m => m.Idvn == vote.IDVN);
                 EmailSender.SendVoteResponse(user.Email, "Votul dumneavoastră a fost înregistrat cu succes!");
             }
             catch (Exception)
             { }
         }
     }
     else
     {
         using (var db = new SystemDBContext())
         {
             try
             {
                 var user = db.IdvnAccounts.FirstOrDefault(m => m.Idvn == vote.IDVN);
                 EmailSender.SendVoteResponse(user.Email, "Votul dumneavoastră nu a fost înregistrat cu succes. Vă rugăm să încercați din nou!");
             }
             catch (Exception)
             { }
         }
     }
 }
Esempio n. 14
0
        public HttpResponseMessage PutChangeType(JToken token)
        {
            HttpResponseMessage msg = new HttpResponseMessage();

            var type     = token.Value <string>("type");
            var username = token.Value <string>("username");

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Vozac vozac = db.Vozaci.FirstOrDefault(x => x.Username == username);

                    if (vozac != null)
                    {
                        vozac.Car.Type = GetType(type);

                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.NoContent);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "There was internal error, drive is deleted.");
                    }
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while finishing");
            }

            return(msg);
        }
        public List <BasicUserInfo> GetAllFriends()
        {
            if (UserToken == null)
            {
                return(new List <BasicUserInfo>());
            }

            using (var db = new SystemDBContext())
            {
                // Player we added
                var userFriend = db.Friends.Where(x => x.Player1HashId == UserToken.UserId).ToList();
                var friends    = userFriend.Select(friendModel => new BasicUserInfo()
                {
                    AreFriend = true,
                    HashId    = friendModel.Player2HashId,
                    Username  = friendModel.Player2Username
                }).ToList();

                // Players who added us
                userFriend = db.Friends.Where(x => x.Player2HashId == UserToken.UserId).ToList();
                friends.AddRange(userFriend.Select(friendModel => new BasicUserInfo()
                {
                    AreFriend = true,
                    HashId    = friendModel.Player1HashId,
                    Username  = friendModel.Player1Username
                }));

                return(friends);
            }
        }
Esempio n. 16
0
        public void ClearAll()
        {
            ClearDatabase();

            using (var context = new SystemDBContext())
            {
                var felixHash = GetFelixHashId();

                // Delete all Users
                foreach (var id in context.Users.Where(x => x.HashId != felixHash).Select(e => e.Id))
                {
                    var entity = new UserModel()
                    {
                        Id = id
                    };
                    context.Users.Attach(entity);
                    context.Users.Remove(entity);
                }

                // Delete all Profiles
                foreach (var id in context.Profiles.Where(x => x.UserHashId != felixHash).Select(e => e.Id))
                {
                    var entity = new ProfileModel()
                    {
                        Id = id
                    };
                    context.Profiles.Attach(entity);
                    context.Profiles.Remove(entity);
                }

                context.SaveChanges();
            }
        }
Esempio n. 17
0
        public HttpResponseMessage PostLocation([FromBody] Adresa address)
        {
            HttpResponseMessage msg  = new HttpResponseMessage();
            LokacijaRepository  repo = new LokacijaRepository();

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Lokacija lk = new Lokacija()
                    {
                        Address = new Adresa()
                        {
                            FullAddress = address.FullAddress
                        },
                        CoordinateX = 0,
                        CoordinateY = 0,
                        LocationId  = repo.GetLokacije().Count + 1
                    };

                    db.Lokacije.Add(lk);
                    db.SaveChanges();

                    msg = Request.CreateResponse(HttpStatusCode.Created, lk.LocationId); //vracam ID sacuvane lokacije
                    msg.Headers.Location = new Uri(Request.RequestUri + lk.LocationId.ToString());
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while updating");
            }

            return(msg);
        }
Esempio n. 18
0
        private HttpResponseMessage UpdateUser(Vozac sentObj, Roles role, HttpResponseMessage msg)
        {
            using (SystemDBContext db = new SystemDBContext())
            {
                if (role == Roles.Admin)
                {
                    Admin a = db.Admini.FirstOrDefault(x => x.Username == sentObj.Username);

                    a.PhoneNumber = sentObj.PhoneNumber;
                    a.Password    = sentObj.Password;
                    a.Name        = sentObj.Name;
                    a.Lastname    = sentObj.Lastname;
                    a.Jmbg        = sentObj.Jmbg;
                    a.Gender      = sentObj.Gender;
                    a.Email       = sentObj.Email;

                    msg = Request.CreateResponse(HttpStatusCode.OK, a);
                    msg.Headers.Location = new Uri(Request.RequestUri + a.Username);
                }
                else if (role == Roles.Customer)
                {
                    Musterija m = db.Musterije.FirstOrDefault(x => x.Username == sentObj.Username);

                    m.PhoneNumber = sentObj.PhoneNumber;
                    m.Password    = sentObj.Password;
                    m.Name        = sentObj.Name;
                    m.Lastname    = sentObj.Lastname;
                    m.Jmbg        = sentObj.Jmbg;
                    m.Gender      = sentObj.Gender;
                    m.Email       = sentObj.Email;

                    msg = Request.CreateResponse(HttpStatusCode.OK, m);
                    msg.Headers.Location = new Uri(Request.RequestUri + m.Username);
                }
                else
                {
                    Vozac v = db.Vozaci.FirstOrDefault(x => x.Username == sentObj.Username);

                    v.PhoneNumber = sentObj.PhoneNumber;
                    v.Password    = sentObj.Password;
                    v.Name        = sentObj.Name;
                    v.Lastname    = sentObj.Lastname;
                    v.Jmbg        = sentObj.Jmbg;
                    v.Gender      = sentObj.Gender;
                    v.Email       = sentObj.Email;

                    v.Location = sentObj.Location;

                    msg = Request.CreateResponse(HttpStatusCode.OK, v);
                    msg.Headers.Location = new Uri(Request.RequestUri + v.Username);
                }

                db.SaveChanges();
            }

            return(msg);
        }
        public ProfileModel UpdateMyProfile(ProfileModel newProfile)
        {
            if (UserToken == null)
            {
                throw HttpResponseExceptionHelper.Create("User token not specified", HttpStatusCode.BadRequest);
            }
            using (var db = new SystemDBContext())
            {
                var profile = db.Profiles.FirstOrDefault(x => x.UserHashId == UserToken.UserId);
                if (profile == null)
                {
                    throw HttpResponseExceptionHelper.Create("No profile exist with specified user Id",
                                                             HttpStatusCode.BadRequest);
                }


                // Modify profile
                if (newProfile == null)
                {
                    throw HttpResponseExceptionHelper.Create("Invalid providen profile",
                                                             HttpStatusCode.BadRequest);
                }

                profile.IsPrivate   = newProfile.IsPrivate;
                profile.Description = newProfile.Description;
                profile.Picture     = newProfile.Picture;

                if ((int)newProfile.PrincessTitle > (int)profile.PrincessTitle)
                {
                    profile.PrincessTitle = newProfile.PrincessTitle;
                }

                if (newProfile.Experience > profile.Experience)
                {
                    profile.Experience = newProfile.Experience;
                }

                if (newProfile.Level > profile.Level)
                {
                    profile.Level = newProfile.Level;
                }

                if (!string.IsNullOrWhiteSpace(newProfile.StatsString))
                {
                    profile.StatsString = newProfile.StatsString;
                }

                if (!string.IsNullOrWhiteSpace(newProfile.AchievementsString) && !newProfile.AchievementsString.Contains("null"))
                {
                    profile.AchievementsString = newProfile.AchievementsString;
                }

                // call SaveChanges
                db.SaveChanges();
                return(profile);
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            var context  = new SystemDBContext();
            var students = context.Students.ToList();

            students.ForEach(s =>
            {
                Console.WriteLine("Name: {0} Birthday: {1:dd-MM-yy}", s.Name, s.Birthday);
            });
        }
        public void CompleteDaily()
        {
            var daily = GetTodayDaily();

            using (var db = new SystemDBContext())
            {
                daily        = db.Daylies.Find(daily.Id);
                daily.IsDone = true;
                db.SaveChanges();
            }
        }
        public void PrepareVoteResponse(string content)
        {
            NodeVoteResponse response;

            try
            {
                response = JsonConvert.DeserializeObject <NodeVoteResponse>(content);
                SendMessage(response);
            }
            catch (JsonException e)
            {
                _logger.Error(e);
                throw e;
            }

            using (var db = new SystemDBContext())
            {
                VoteStatus voteStatus = new VoteStatus
                {
                    Idvn      = response.IDVN,
                    VoteState = "Voted"
                };

                Block block = new Block
                {
                    //  BlockId = response.block.BlockId,
                    CreatedOn    = (DateTime)response.block.CreatedOn,
                    PartyId      = (int)response.block.PartyChoosed,
                    Gender       = response.block.Gender,
                    Hash         = response.block.Hash,
                    Idbd         = response.block.Idbd,
                    PreviousHash = response.block.PreviousHash,
                    RegionId     = (int)response.block.RegionChoosed,
                    YearBirth    = 1999// (int)response.block.YearBirth
                };
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Add(voteStatus);
                        db.Add(block);
                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        _logger.Error(e);
                        Console.WriteLine(e);
                    }
                }
            }
        }
Esempio n. 23
0
        public void ClearDatabase()
        {
            using (var context = new SystemDBContext())
            {
                var felixHash = GetFelixHashId();
                // Delete all Maps
                foreach (var id in context.Maps.Where(x => x.CreatorhashId != felixHash).Select(e => e.Id))
                {
                    var entity = new MapModel()
                    {
                        Id = id
                    };
                    context.Maps.Attach(entity);
                    context.Maps.Remove(entity);
                }


                // Delete all Dailies
                foreach (var id in context.Daylies.Where(x => x.UserHashId != felixHash).Select(e => e.Id))
                {
                    var entity = new DailyModel()
                    {
                        Id = id
                    };
                    context.Daylies.Attach(entity);
                    context.Daylies.Remove(entity);
                }

                // Delete all Leaderboards
                foreach (var id in context.Leaderboards.Select(e => e.Id))
                {
                    var entity = new LeaderboardModel()
                    {
                        Id = id
                    };
                    context.Leaderboards.Attach(entity);
                    context.Leaderboards.Remove(entity);
                }

                // Delete all Friends
                foreach (var id in context.Friends.Select(e => e.Id))
                {
                    var entity = new FriendModel()
                    {
                        Id = id
                    };
                    context.Friends.Attach(entity);
                    context.Friends.Remove(entity);
                }

                context.SaveChanges();
            }
        }
        public void DeleteAllDaily()
        {
            using (var db = new SystemDBContext())
            {
                var dailies = db.Daylies.Where(x => x.UserHashId == UserToken.UserId).ToList();

                foreach (var daily in dailies)
                {
                    db.Daylies.Remove(daily);
                }
                db.SaveChanges();
            }
        }
        /// <summary>
        /// Get the basic information of all the specified user maps
        /// </summary>
        /// <returns></returns>
        public List <MapModel> GetUserMaps(string userId)
        {
            using (var db = new SystemDBContext())
            {
                var maps = db.Maps.Where(x => x.CreatorhashId == userId).ToList();

                foreach (var map in maps)
                {
                    map.Content = "";
                }

                return(maps);
            }
        }
Esempio n. 26
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //ukoliko menjamo tabelu nakon sto je napravljena, mora da se dropuje i kreira nova
            Database.SetInitializer(new SystemSeeder());

            //programsko ucitavanje admina
            string[] info = new string[10];
            string   path = AppDomain.CurrentDomain.BaseDirectory + "Admini.txt";

            using (StreamReader sr = File.OpenText(path))
            {
                string s = String.Empty;
                while ((s = sr.ReadLine()) != null)
                {
                    info = s.Split(';');
                    try //samo jendom ce dodati admine, sledeci put nece, zbog jedinstvenosti kljuca
                    {
                        using (SystemDBContext db = new SystemDBContext())
                        {
                            Admin a = new Admin()
                            {
                                Username    = info[0],
                                Password    = info[1],
                                Name        = info[2],
                                Lastname    = info[3],
                                Gender      = (Genders)Enum.Parse(typeof(Genders), info[4]),
                                Jmbg        = info[5],
                                PhoneNumber = info[6],
                                Email       = info[7],
                                Role        = (Roles)Enum.Parse(typeof(Roles), info[8]),
                                DriveStatus = (DrivingStatus)Enum.Parse(typeof(DrivingStatus), info[9]),
                            };

                            db.Admini.Add(a);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine($"Error - {e.Message}");
                    }
                }
            }
        }
        /// <summary>
        /// Only map who are created by public profiles
        /// </summary>
        /// <returns></returns>
        public List <MapModel> GetAllPublicZones()
        {
            using (var db = new SystemDBContext())
            {
                var publicProfilesHash = db.Profiles.Where(x => x.IsPrivate == false).Select(X => X.UserHashId).ToList();
                var maps = db.Maps.Where(map => publicProfilesHash.Contains(map.CreatorhashId)).ToList();

                foreach (var map in maps)
                {
                    map.Content = "";
                }

                return(maps);
            }
        }
        /// <summary>
        /// Get all the info related to a specified map hash id
        /// </summary>
        /// <param name="mapHashId"></param>
        /// <returns></returns>
        public MapModel GetMap(string mapHashId)
        {
            using (var db = new SystemDBContext())
            {
                var map = db.Maps.FirstOrDefault(x => x.HashId == mapHashId);

                if (map == null)
                {
                    throw HttpResponseExceptionHelper.Create("No map correspond to the given hashId",
                                                             HttpStatusCode.BadRequest);
                }

                return(map);
            }
        }
Esempio n. 29
0
        public HttpResponseMessage PostMusterija([FromBody] JToken token)
        {
            HttpResponseMessage msg;
            VoznjaRepository    repo = new VoznjaRepository();

            var start     = token.Value <int>("start");
            var driver    = token.Value <string>("user");
            var type      = token.Value <string>("type");
            var admin     = token.Value <string>("admin");
            var adminSts  = token.Value <int>("adminStatus");
            var driverSts = token.Value <int>("driverStatus");

            TypeOfCar typeC = GetTypeInEnum(type);

            try
            {
                using (var db = new SystemDBContext())
                {
                    Voznja v = new Voznja()
                    {
                        StartPointID      = start,
                        DriverID          = driver,
                        TypeOfCar         = typeC,
                        Id                = repo.GetVoznje().Count + 1,
                        Status            = GetStatus(adminSts),
                        TimeOfReservation = DateTime.Now,
                        AdminID           = admin
                    };

                    Vozac voz = db.Vozaci.FirstOrDefault(x => x.Username == driver);
                    voz.DriveStatus = GetStatus(driverSts);
                    Admin a = db.Admini.FirstOrDefault(x => x.Username == admin);
                    a.DriveStatus = GetStatus(adminSts);

                    db.Voznje.Add(v);
                    db.SaveChanges();

                    msg = Request.CreateResponse(HttpStatusCode.Created, v);
                    msg.Headers.Location = new Uri(Request.RequestUri + v.Id.ToString());

                    return(msg);
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Esempio n. 30
0
        private string GetFelixHashId()
        {
            using (var context = new SystemDBContext())
            {
                var felixHash      = "";
                var firstOrDefault = context.Users
                                     .FirstOrDefault(x => x.Username.ToLower() == "felix");

                if (firstOrDefault != null)
                {
                    felixHash = firstOrDefault.HashId;
                }

                return(felixHash);
            }
        }