コード例 #1
0
        public static void SavePCCaseToDB(string partid)
        {
            JObject  chosenpart = GetPartData(partid);
            Entities ORM        = new Entities();

            PCCase tempObj = new PCCase(chosenpart["title"].ToString());

            List <PCCase> z = new List <PCCase>();

            z = ORM.PCCases.Where(x => x.ProductID == partid).ToList();

            if (z.Count < 1)
            {
                tempObj.ProductID   = chosenpart["product_id"].ToString();
                tempObj.Description = "x";
                tempObj.Brand       = chosenpart["brand"].ToString();
                tempObj.Price       = int.Parse(chosenpart["price"].ToString());
                try { tempObj.Stars = float.Parse(chosenpart["stars"].ToString()); }
                catch { tempObj.Stars = null; }
                tempObj.Stars          = float.Parse(chosenpart["stars"].ToString());
                tempObj.ImageLink      = chosenpart["main_image"].ToString();
                tempObj.Manufacturer   = "x";
                tempObj.Width          = null;
                tempObj.TwoSlots       = null;
                tempObj.ThreeSlots     = null;
                tempObj.Style          = null;
                tempObj.Length         = null;
                tempObj.Height         = null;
                tempObj.ExpansionSlots = null;

                ORM.PCCases.Add(tempObj);
                ORM.SaveChanges();
            }
        }
コード例 #2
0
        public async Task <IActionResult> Edit(Guid id, PCCase model)
        {
            try
            {
                if (model == null)
                {
                    return(this.NotFound());
                }

                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                model.PCCaseId = id;

                string accessToken = await this.HttpContext.GetTokenAsync("access_token");

                await ApiRequests.PutAsync(accessToken, string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), model);

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create(PCCase model)
        {
            try
            {
                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                using (var httpClient = new HttpClient())
                {
                    var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

                    using (HttpResponseMessage response = await httpClient.PostAsync(string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), content))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        //receivedReservation = JsonConvert.DeserializeObject<Reservation>(apiResponse);
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
コード例 #4
0
ファイル: PCCaseService.cs プロジェクト: Fargose/FerumChecker
        public OperationDetails CreatePCCase(PCCase pcCase)
        {
            Database.PCCases.Create(pcCase);
            SetMotherBoardFormFactors(pcCase, (List <PCCaseMotherBoardFormFactor>)pcCase.PCCaseMotherBoardFormFactors);
            SetOuterMemoryFormFactors(pcCase, (List <PCCaseOuterMemoryFormFactor>)pcCase.PCCaseOuterMemoryFormFactors);
            Database.Save();

            return(new OperationDetails(true, "Ok", ""));
        }
コード例 #5
0
        // GET: PCCases/Edit/5
        public async Task <IActionResult> Edit(Guid id)
        {
            string accessToken = await this.HttpContext.GetTokenAsync("access_token");

            string response = await ApiRequests.GetAsync(accessToken, string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id));

            PCCase pcCase = JsonConvert.DeserializeObject <PCCase>(response);

            return(this.View(pcCase));
        }
コード例 #6
0
 public Configuration()
 {
     Fan          = new Fan();
     GraphicsCard = new GraphicsCard();
     Motherboard  = new Motherboard();
     PCCase       = new PCCase();
     PowerSupply  = new PowerSupply();
     Processor    = new Processor();
     RAM          = new RAM();
 }
コード例 #7
0
ファイル: PCCaseService.cs プロジェクト: Fargose/FerumChecker
 public OperationDetails UpdatePCCase(PCCase pcCase)
 {
     Database.PCCases.Update(pcCase);
     SetMotherBoardFormFactors(pcCase, (List <PCCaseMotherBoardFormFactor>)pcCase.PCCaseMotherBoardFormFactors);
     SetOuterMemoryFormFactors(pcCase, (List <PCCaseOuterMemoryFormFactor>)pcCase.PCCaseOuterMemoryFormFactors);
     Database.Save();
     pcCase = GetPCCase(pcCase.Id);
     _computerAssemblyService.OnPCCaseChange(pcCase);
     Database.Save();
     return(new OperationDetails(true, "Ok", ""));
 }
コード例 #8
0
        public async Task <ActionResult <PCCase> > Get(Guid Id)
        {
            PCCase pcCase = await this._repository.Get(Id);

            if (pcCase == null)
            {
                return(this.NotFound());
            }

            return(pcCase);
        }
コード例 #9
0
        //[ValidateAntiForgeryToken]
        public IActionResult Create(PCCaseViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.PCCaseOuterMemoryFormFactors == null)
                {
                    model.PCCaseOuterMemoryFormFactors = new List <OuterMemoryFormFactorViewModel>();
                }
                if (model.PCCaseMotherBoardFormFactors == null)
                {
                    model.PCCaseMotherBoardFormFactors = new List <MotherBoardFormFactorViewModel>();
                }
                var helper = new ImageHelper(_webHostEnvironment);
                var image  = helper.GetUploadedFile(model.Image, "PCCase");
                var pcCase = new PCCase()
                {
                    Name           = model.Name,
                    Description    = model.Description,
                    Weight         = model.Weight,
                    ManufacturerId = model.ManufacturerId,
                    Image          = image,
                    Price          = model.Price
                };

                pcCase.PCCaseMotherBoardFormFactors = model.PCCaseMotherBoardFormFactors.Select(m => new PCCaseMotherBoardFormFactor()
                {
                    MotherBoardFormFactorId = m.Id
                }).ToList();
                pcCase.PCCaseOuterMemoryFormFactors = model.PCCaseOuterMemoryFormFactors.Select(m => new PCCaseOuterMemoryFormFactor()
                {
                    OuterMemoryFormFactorId = m.Id
                }).ToList();
                var result = _pcCaseService.CreatePCCase(pcCase);

                if (result.Succedeed)
                {
                    return(View("../Catalog/Index", new { startView = "PCCase" }));
                }

                return(NotFound(result));
            }
            var motherBoardFormFactorService = _motherBoardFormFactorService.GetMotherBoardFormFactors();

            ViewBag.MotherBoardFormFactors = new SelectList(motherBoardFormFactorService, "Id", "Name");
            var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors();

            ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            return(View(model));
        }
コード例 #10
0
        public async Task <IActionResult> Delete(Guid id, PCCase pcCase = null)
        {
            try
            {
                string accessToken = await this.HttpContext.GetTokenAsync("access_token");

                await ApiRequests.DeleteAsync(accessToken, string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id));

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
コード例 #11
0
        // GET: PCCases/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var pcCase = new PCCase();

            using (var httpClient = new HttpClient())
            {
                using (HttpResponseMessage response = await httpClient.GetAsync(string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id)))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    pcCase = JsonConvert.DeserializeObject <PCCase>(apiResponse);
                }
            }

            return(this.View(pcCase));
        }
コード例 #12
0
        public async Task <ActionResult <PCCase> > Post([FromBody] PCCase model)
        {
            try
            {
                model.CreatedDate  = DateTime.UtcNow;
                model.ModifiedDate = DateTime.UtcNow;

                await this._repository.Add(model);

                return(this.StatusCode(StatusCodes.Status201Created, model));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
コード例 #13
0
        public async Task <ActionResult <PCCase> > Delete(Guid Id)
        {
            try
            {
                PCCase pcCase = await this._repository.Delete(Id);

                if (pcCase == null)
                {
                    return(this.StatusCode(StatusCodes.Status404NotFound));
                }
                return(this.StatusCode(StatusCodes.Status200OK));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
コード例 #14
0
ファイル: PCCaseService.cs プロジェクト: Fargose/FerumChecker
        private OperationDetails SetMotherBoardFormFactors(PCCase pcCase, List <PCCaseMotherBoardFormFactor> outerMemories)
        {
            if (pcCase.Id > -1 && outerMemories != null)
            {
                var oldMotherBoardFormFactors = Database.PCCaseMotherBoardFormFactors.GetAll().Where(m => m.PCCaseId == pcCase.Id);
                foreach (var item in oldMotherBoardFormFactors)
                {
                    Database.PCCaseMotherBoardFormFactors.Delete(item.Id);
                }
                foreach (var item in outerMemories)
                {
                    item.PCCaseId = pcCase.Id;
                    this.Database.PCCaseMotherBoardFormFactors.Create(item);
                }
            }

            return(new OperationDetails(true, "Ok", ""));
        }
コード例 #15
0
        public async Task <IActionResult> Delete(Guid id, PCCase pcCase = null)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    using (HttpResponseMessage response = await httpClient.DeleteAsync(string.Format("{0}/{1}/{2}", this.apiBaseUrl, this.apiController, id)))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }
コード例 #16
0
        public async Task <IActionResult> Put([FromBody] PCCase model)
        {
            try
            {
                if (model != null)
                {
                    model.ModifiedDate = DateTime.UtcNow;

                    await this._repository.Update(model);

                    return(this.StatusCode(StatusCodes.Status201Created, model));
                }

                return(this.StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
コード例 #17
0
        public static void SavePCCasesToDB()
        {
            List <JObject> searchedparts = new List <JObject>();

            searchedparts = GetPartData(GetParts("Computer+Case"));
            Entities ORM = new Entities();

            foreach (JObject part in searchedparts)
            {
                string y          = part["product_id"].ToString();
                PCCase tempPCCase = new PCCase(part["title"].ToString());

                List <PCCase> z = new List <PCCase>();
                z = ORM.PCCases.Where(x => x.ProductID == y).ToList();

                if (z.Count < 1)
                {
                    tempPCCase.ProductID   = part["product_id"].ToString();
                    tempPCCase.Description = "x";//part["product_description"].ToString();
                    tempPCCase.Brand       = part["brand"].ToString();
                    tempPCCase.Price       = int.Parse(part["price"].ToString());
                    try { tempPCCase.Stars = float.Parse(part["stars"].ToString()); }
                    catch { tempPCCase.Stars = null; }
                    tempPCCase.ImageLink      = part["main_image"].ToString();
                    tempPCCase.Manufacturer   = "x";
                    tempPCCase.Width          = null;
                    tempPCCase.TwoSlots       = null;
                    tempPCCase.ThreeSlots     = null;
                    tempPCCase.Style          = null;
                    tempPCCase.Length         = null;
                    tempPCCase.Height         = null;
                    tempPCCase.ExpansionSlots = null;

                    ORM.PCCases.Add(tempPCCase);
                    ORM.SaveChanges();
                }
            }
        }
コード例 #18
0
        public async Task <IActionResult> Edit(Guid id, PCCase model)
        {
            try
            {
                if (model == null)
                {
                    return(this.NotFound());
                }

                if (model.ImageFile != null)
                {
                    model.ImageTitle = model.ImageFile.FileName;
                    model.ImageData  = ImageManager.GetByteArrayFromImage(model.ImageFile);
                }

                using (var httpClient = new HttpClient())
                {
                    model.PCCaseId = id;
                    string json        = JsonConvert.SerializeObject(model, Formatting.Indented);
                    var    httpContent = new StringContent(json, Encoding.UTF8, "application/json");

                    using (HttpResponseMessage response = await httpClient.PutAsync(string.Format("{0}/{1}", this.apiBaseUrl, this.apiController), httpContent))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();    // returns object, todo: change response in api to return successfull message

                        //ViewBag.Result = "Success";
                        //receivedReservation = JsonConvert.DeserializeObject<Reservation>(apiResponse);
                    }
                }

                return(this.RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(this.View());
            }
        }