Ejemplo n.º 1
0
        public ActionResult PostDlc(string username, [FromBody] int id)
        {
            UserDlc userDlc;

            try
            {
                User user = Repo.GetUser(username);
                Dlc  dlc  = Repo.GetDlc(id);
                if (user == null || dlc == null)
                {
                    return(StatusCode(400));
                }
                userDlc = new UserDlc {
                    User = user, Dlc = dlc
                };
                bool check = Repo.AddUserDlc(userDlc);
                //check is for checking if the username already exists, and if it does return status code 409
                if (!check)
                {
                    return(StatusCode(409));
                }
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            return(CreatedAtRoute("GetUserDlc", new { username = userDlc.User.UserName, id = userDlc.Dlc.Dlcid }, userDlc));
        }
Ejemplo n.º 2
0
        void TestIsReady(int errorCode)
        {
            if (errorCode == SUCCESS)
            {
                TestLogger.Success("IsReady", "IsReady success.");
                var dlcCount = Dlc.GetCount();
                TestLogger.Success("GetCount", dlcCount.ToString());
                for (var i = 0; i < dlcCount; i++)
                {
                    var  viveporId      = string.Empty;
                    var  isAvailable    = false;
                    bool isNotOverRange = Dlc.GetIsAvailable(i, out viveporId, out isAvailable);
                    if (isNotOverRange)
                    {
                        TestLogger.Success("GetIsAvailable", string.Format("VIVEPORT ID: {0}, Is Available: {1}", viveporId, isAvailable));
                    }
                    else
                    {
                        TestLogger.Error("GetIsAvailable", "Index is out of range.");
                        break;
                    }
                }
            }
            else
            {
                TestLogger.Error("IsReady", string.Format("IsReady failure. Error Code: {0}", errorCode));
            }

            Api.Shutdown(TestShutdownCallback);
        }
        public ActionResult Put(int id, [FromBody] Dlc value)
        {
            Dlc dlc;

            try
            {
                dlc = Repo.GetDlc(id);
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            if (dlc == null)
            {
                return(NotFound());
            }
            if (dlc.Dlcid != value.Dlcid)
            {
                return(BadRequest("cannot change ID"));
            }
            try
            {
                Repo.UpdateDlc(value);
            }
            catch (Exception ex)
            {
                // internal server error
                return(StatusCode(500));
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(FullDlc fulldlc)
        {
            Dlc dlc = fulldlc.Dlc;

            try
            {
                HttpRequestMessage  request  = CreateRequest(HttpMethod.Post, "api/Dlc", dlc);
                HttpResponseMessage response = await Client.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                    return(RedirectToAction("Error", "Home"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "IdDlc,NomeDlc,DescricaoDlc,PrecoDlc,IdJogo")] DlcViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         Dlc dlc = Mapper.Map <DlcViewModel, Dlc>(viewModel);
         repositorioDlc.Alterar(dlc);
         return(RedirectToAction("Index"));
     }
     //ViewBag.IdJogo = new SelectList(db.Jogo, "Id", "Nome", dlc.IdJogo);
     return(View(viewModel));
 }
Ejemplo n.º 6
0
 public DlcViewModel(Dlc dlc)
 {
     Id           = dlc.Id;
     ParentGameId = dlc.ParentGameId;
     Name         = dlc.Name;
     Owned        = dlc.Owned;
     Price        = dlc.Price;
     Notes        = dlc.Notes;
     Rating       = dlc.Rating;
     Ranking      = dlc.Ranking;
     Store        = dlc.Store;
 }
Ejemplo n.º 7
0
        public void AddFavorite(Dlc dlc)
        {
            lock (FavoriteDlcs) {
                if (FavoriteDlcs.Any(f => f.Matches(dlc)))
                {
                    return;
                }
                FavoriteDlcs.Add(new FavoriteDlc(dlc));
            }

            SaveSettings();
        }
Ejemplo n.º 8
0
 void TestInitCallback(int errorCode)
 {
     if (errorCode == SUCCESS)
     {
         TestLogger.Success("Init", "Init success.");
         Dlc.IsReady(TestIsReady);
     }
     else
     {
         TestLogger.Error("Init", string.Format("Init failure. Error Code: {0}", errorCode));
     }
 }
Ejemplo n.º 9
0
        public void RemoveFavorite(Dlc dlc)
        {
            lock (FavoriteDlcs) {
                var favorite = FavoriteDlcs.FirstOrDefault(f => f.Matches(dlc));
                if (favorite == null)
                {
                    return;
                }
                FavoriteDlcs.Remove(favorite);
            }

            SaveSettings();
        }
Ejemplo n.º 10
0
        // GET: Dlcs/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dlc dlc = repositorioDlc.SelecionarPorId((int)id.Value);

            if (dlc == null)
            {
                return(HttpNotFound());
            }
            return(View(Mapper.Map <Dlc, DlcIndexViewModel>(dlc)));
        }
Ejemplo n.º 11
0
        public static void GenerateFilter(Dlc dlc, int amountTracks, int amountCars)
        {
            Random     rdm = new Random();
            string     input;
            List <Car> _modifiedCars = new List <Car>();

            //Filter lists
            foreach (Car car in _cars)
            {
                if (!car.IsDlc)
                {
                    continue;
                }
                if (car.DlcPack == dlc)
                {
                    _modifiedCars.Add(car);
                }
            }

            do
            {
                string        strCar;
                StringBuilder strCircuit = new StringBuilder();
                for (int i = 0; i < amountCars; i++)
                {
                    int rdmCar = rdm.Next(_modifiedCars.Count - 1);
                    strCar = $"Car{i + 1}: {_modifiedCars[rdmCar].Brand} {_modifiedCars[rdmCar].Model} {_modifiedCars[rdmCar].Year}";
                    if (_modifiedCars[rdmCar].IsDlc)
                    {
                        strCar += _modifiedCars[rdmCar].DlcPack;
                    }

                    strCar += "\n";
                }
            } while (input != null && input.ToLower() != "n");



            string        strCar     = "";
            StringBuilder strCircuit = new StringBuilder();

            for (int i = 0; i < amountCars; i++)
            {
            }
        }
        public ActionResult Post([FromBody] Dlc dlc)
        {
            try
            {
                bool check = Repo.AddDlc(dlc);
                //check is for checking if the username already exists, and if it does return status code 409
                if (!check)
                {
                    return(StatusCode(409));
                }
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            return(CreatedAtRoute("GetDlc", new { id = dlc.Dlcid }, dlc));
        }
Ejemplo n.º 13
0
        // GET: Dlcs/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dlc dlc = repositorioDlc.SelecionarPorId((int)id.Value);

            if (dlc == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.IdJogo = new SelectList(db.Jogo, "Id", "Nome", dlc.IdJogo);
            List <JogoIndexViewModel> jogos = Mapper.Map <List <Jogo>,
                                                          List <JogoIndexViewModel> >(repositorioJogo.Selecionar());

            SelectList dropDownJogos = new SelectList(jogos, "Id", "Nome");

            ViewBag.DropDownJogos = dropDownJogos;
            return(View(Mapper.Map <Dlc, DlcViewModel>(dlc)));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> Edit(int id, Dlc dlc)
        {
            try
            {
                HttpRequestMessage  request  = CreateRequest(HttpMethod.Put, $"api/Dlc/{id}", dlc);
                HttpResponseMessage response = await Client.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                    return(View());
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        // GET: UserDlc/Create
        public async Task <ActionResult> Purchase(int id)
        {
            string username = ViewBag.LoggedInUser;

            if (username == "")
            {
                return(RedirectToAction("Login", "Account"));
            }

            HttpRequestMessage request  = CreateRequest(HttpMethod.Get, $"api/Dlc/{id}");
            HttpRequestMessage request2 = CreateRequest(HttpMethod.Get, $"api/User/{username}");

            HttpResponseMessage response = await Client.SendAsync(request);

            HttpResponseMessage response2 = await Client.SendAsync(request2);

            if (!response.IsSuccessStatusCode || !response2.IsSuccessStatusCode)
            {
                if (response.StatusCode == HttpStatusCode.Unauthorized || response2.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                return(RedirectToAction("Error", "Home"));
            }
            string resString = await response.Content.ReadAsStringAsync();

            string resString2 = await response2.Content.ReadAsStringAsync();


            Dlc  dlc  = JsonConvert.DeserializeObject <Dlc>(resString);
            User user = JsonConvert.DeserializeObject <User>(resString2);

            return(View(new UserDlc {
                Dlc = dlc, User = user
            }));
        }
Ejemplo n.º 16
0
 public bool IsFavorite(Dlc dlc) {
     return FavoriteDlcs.Any(f => f.Matches(dlc));
 }
Ejemplo n.º 17
0
 public FavoriteDlc(Dlc dlc) {
     _Uuid = dlc.Id;
 }
Ejemplo n.º 18
0
        public void AddFavorite(Dlc dlc) {
            lock (FavoriteDlcs) {
                if (FavoriteDlcs.Any(f => f.Matches(dlc)))
                    return;
                FavoriteDlcs.Add(new FavoriteDlc(dlc));
            }

            SaveSettings();
        }
Ejemplo n.º 19
0
 public bool IsFavorite(Dlc dlc) => FavoriteDlcs.Any(f => f.Matches(dlc));
Ejemplo n.º 20
0
 void AfterDlcDataModelMap(Dlc src, DlcDataModel dest)
 {
     Map(src.MetaData, dest);
 }
Ejemplo n.º 21
0
        public void RemoveFavorite(Dlc dlc) {
            lock (FavoriteDlcs) {
                var favorite = FavoriteDlcs.FirstOrDefault(f => f.Matches(dlc));
                if (favorite == null)
                    return;
                FavoriteDlcs.Remove(favorite);
            }

            SaveSettings();
        }
Ejemplo n.º 22
0
 public FavoriteDlc(Dlc dlc)
 {
     _Uuid = dlc.Id;
 }
Ejemplo n.º 23
0
 public bool IsFavorite(Dlc dlc) => FavoriteDlcs.Any(f => f.Matches(dlc));
Ejemplo n.º 24
0
 InstalledDlc CreateInstalledDlc(Dlc dlc) => new InstalledDlc { Id = dlc.Id };
Ejemplo n.º 25
0
 public bool Matches(Dlc dlc) => dlc != null && dlc.Id == _Uuid;
Ejemplo n.º 26
0
 InstalledDlc CreateInstalledDlc(Dlc dlc) {
     return new InstalledDlc {Id = dlc.Id};
 }
Ejemplo n.º 27
0
 public static string GetTitle(this Dlc dlc)
 {
     return(nameList[(int)dlc]);
 }
Ejemplo n.º 28
0
 void AfterDlcDataModelMap(Dlc src, DlcDataModel dest) {
     Map(src.MetaData, dest);
 }
Ejemplo n.º 29
0
 public bool Matches(Dlc dlc) {
     return dlc != null && dlc.Id == _Uuid;
 }
Ejemplo n.º 30
0
 InstalledDlc CreateInstalledDlc(Dlc dlc) => new InstalledDlc
 {
     Id = dlc.Id
 };
Ejemplo n.º 31
0
 private void CreateDlcPack(string savePath)
 {
     Dlc.Create(dlcType, dlcName, savePath);
 }
Ejemplo n.º 32
0
 public bool Matches(Dlc dlc) => dlc != null && dlc.Id == _Uuid;