//public void DeleteSculpture(int sculp_Id) //{ // using (var client = new HttpClient(handler)) // { // client.BaseAddress = new Uri(ServerUrl); // client.DefaultRequestHeaders.Clear(); // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // try // { // string deleteUrl = "api/Sculptures" + sculp_Id; // var response = client.DeleteAsync(deleteUrl).Result; // if (response.IsSuccessStatusCode) // { // new MessageDialog("Succesfull delete"); // } // else // { // new MessageDialog("Something went wrong,sculpture not deleted"); // } // } // catch (Exception ex) // { // new MessageDialog("Something went wrong,sculpture not deleted"); // } // } //} public void DeleteSculpture(Sculpture SelectedSculpture) { using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { string deleteUrl = "api/Sculptures/" + SelectedSculpture.Sculpture_Id; var response = client.DeleteAsync(deleteUrl).Result; if (response.IsSuccessStatusCode) { new MessageDialog("Succesfull delete"); } else { new MessageDialog("Something went wrong,sculpture not deleted"); } } catch (Exception ex) { new MessageDialog("Something went wrong,sculpture not deleted"); } } }
public void UpdateSculpture(Sculpture sculptureToUpdate) { using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //we have to serialize the sculture object into json format string jsonSculptureToUpdate = JsonConvert.SerializeObject(sculptureToUpdate); //Create the content we want to send with the Http put request StringContent content = new StringContent(jsonSculptureToUpdate, Encoding.UTF8, "Application/json"); //Using a Http Put Request we can update the sculpture number 3 var updateResponse = client.PutAsync("api/Sculptures/" + sculptureToUpdate.Sculpture_Id, content).Result; var result = updateResponse.StatusCode; //var response = client.GetAsync("api/Sculpture").Result; //if (response.IsSuccessStatusCode) //{ // var sculptureList = response.Content.ReadAsAsync<IEnumerable<Sculpture>>().Result; // return sculptureList.ToList(); //} } catch (Exception ex) { new MessageDialog(ex.Message).ShowAsync(); } } }
public IHttpActionResult PostSculpture(Sculpture sculpture) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(BadRequest(ModelState)); } db.Sculptures.Add(sculpture); try { db.SaveChanges(); } catch (DbUpdateException) { if (SculptureExists(sculpture.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = sculpture.Id }, sculpture)); }
public SculptureViewModel() { SculptureCatalogSingleton = SculptureCatalogSingleton.Instance; SculptureHandler = new Handler.SculptureHandler(this); NewSculpture = new Sculpture(); CreateCommand = new RelayCommand(SculptureHandler.CreateSculpture); }
public IHttpActionResult PutSculpture(int id, Sculpture sculpture) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sculpture.Id) { return(BadRequest()); } db.Entry(sculpture).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SculptureExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
//public void CreateSculpture() //{ // Sculpture sculpture = new Sculpture(); // new PersistenceFacade().SaveSculpture(sculpture); // var sculptures = new PersistenceFacade().GetSculptures(); // SculptureViewModel.SculptureCatalogSingleton.Sculptures.Clear(); // foreach (var sculpture1 in sculptures) // { // SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture1); // } //} public void CreateSculpture() { Sculpture sculpture = new Sculpture(); sculpture.Sculpture_Id = SculptureViewModel.NewSculpture.Sculpture_Id; sculpture.Sculpture_Name = SculptureViewModel.NewSculpture.Sculpture_Name; sculpture.Sculpture_Adress = SculptureViewModel.NewSculpture.Sculpture_Adress; sculpture.Sculpture_Placement = SculptureViewModel.NewSculpture.Sculpture_Placement; sculpture.TypeLoc = SculptureViewModel.NewSculpture.TypeLoc; sculpture.Material = SculptureViewModel.NewSculpture.Material; //sculpture.Damages = SculptureViewModel.NewSculpture.Damages; //sculpture.Notes = SculptureViewModel.NewSculpture.Notes; //sculpture.Treatments = SculptureViewModel.NewSculpture.Treatments; new PersistenceFacade().SaveSculpture(sculpture); // SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture); var sculptures = new PersistenceFacade().GetSculptures(); SculptureViewModel.SculptureCatalogSingleton.Sculptures.Clear(); foreach (var sculpture1 in sculptures) { SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture1); } SculptureViewModel.NewSculpture.Sculpture_Id = 0; SculptureViewModel.NewSculpture.Sculpture_Name = ""; SculptureViewModel.NewSculpture.Sculpture_Adress = ""; SculptureViewModel.NewSculpture.Sculpture_Placement = ""; SculptureViewModel.NewSculpture.Material = ""; SculptureViewModel.NewSculpture.TypeLoc = ""; // SculptureViewModel.NewSculpture.Damages = new Damage[]; // SculptureViewModel.NewSculpture.Notes = new Note[]; // SculptureViewModel.NewSculpture.Treatments = new Treatment[]; }
protected override void PushData() { base.PushData(); Sculpture work = (Sculpture)_work; work.Weight = float.Parse(weight.Text); work.Material = material.Text; }
protected override void UpdateForm() { base.UpdateForm(); Sculpture work = (Sculpture)_work; weight.Text = work.Weight.ToString(); material.Text = work.Material; }
// Add a new damage to an existing sculpture private static void Exercise3() { Console.WriteLine("Exercise 3"); const string ServerUrl = "http://localhost:3285"; HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //Get the hotel fron the database Console.Write("Enter Id of sculpture no for an existing sculpture:"); int sculpId = int.Parse(Console.ReadLine()); var response = client.GetAsync("api/Sculptures/" + sculpId).Result; if (response.IsSuccessStatusCode) { Sculpture sculptureData = response.Content.ReadAsAsync <Sculpture>().Result; if (sculptureData != null) { Console.WriteLine("Sculpture Id:{0}, Name: {1},Adress: {2}", sculptureData.Sculpture_Id, sculptureData.Sculpture_Name, sculptureData.Sculpture_Adress); Damage d = new Damage(); d.Sculpture = sculptureData; d.Sculpture_Id = sculptureData.Sculpture_Id; Console.Write("Enter damage ID:"); d.Damage_Id = int.Parse(Console.ReadLine()); Console.Write("Enter Damage name:"); d.Damage_Name = Console.ReadLine(); Console.Write("Enter Care name:"); d.Damage_Care = Console.ReadLine(); //The we need to serialize it string newDamagejson = JsonConvert.SerializeObject(d); //Create the content we will send in the Http post request var content = new StringContent(newDamagejson, Encoding.UTF8, "application/json"); var response2 = client.PostAsync("api/damages/PostDamageToExistingSculpture", content).Result; Console.WriteLine("PostAsync"); Console.WriteLine("Status code " + response.StatusCode); if (response2.IsSuccessStatusCode) { //Success , Now we can get the hotel by a Http post Console.WriteLine("Damage created"); Console.WriteLine("Status code " + response2.StatusCode); } } } } catch (Exception ex) { Console.WriteLine("Error exercise 3" + ex.Message); } } Console.ReadLine(); }
public IHttpActionResult GetSculpture(int id) { Sculpture sculpture = db.Sculptures.Find(id); if (sculpture == null) { return(NotFound()); } return(Ok(sculpture)); }
public async Task <IActionResult> PutArtWork(int id, Sculpture artWork) { if (id != artWork.Id) { return(BadRequest("Id sent did not match that of the work")); } data.UpdateWork(artWork); return(NoContent()); }
public IHttpActionResult PostSculpture(Sculpture sculpture) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Sculptures.Add(sculpture); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = sculpture.ID }, sculpture)); }
void Start() { textbox = GetComponent <OutputText>(); sculptureProp = Instantiate(sculptureObject) as GameObject; sculptureProp.AddComponent <Sculpture>(); sculpture = sculptureProp.GetComponent <Sculpture>(); sculpture.SculptureSize(10, 10, 20); sculpture.LoadVoxel(VoxelObject); sculptureProp.transform.position = new Vector3(0, 1, 0); rotSave = sculptureProp.transform.rotation.eulerAngles; rotationY = 0.0f; }
public IHttpActionResult GetSculpture(int id) { Sculpture sculpture = db.Sculptures.Include(d => d.Damages).Include(n => n.Notes).Include(t => t.Treatments).FirstOrDefault(s => s.Id == id); //Sculpture sculpture = db.Sculptures.Find(id); if (sculpture == null) { return(NotFound()); } return(Ok(sculpture)); }
public SculptureViewModel() { SculptureCatalogSingleton = SculptureCatalogSingleton.Instance; SculptureHandler = new Handler.SculptureHandler(this); NewSculpture = new Sculpture(); NewDamage = new Damage(); CreateCommand = new RelayCommand(SculptureHandler.CreateSculpture); ViewSculptureCommand = new RelayCommand(SculptureHandler.ViewSculpture); DeleteCommand = new RelayCommand(SculptureHandler.DeleteSculpture); UpdateCommand = new RelayCommand(SculptureHandler.UpdateSculpture); AddDamageCommand = new RelayCommand(SculptureHandler.AddDamage); }
public void CreateSculpture() { Sculpture sculpture = new Sculpture(); sculpture.C_SculptureID = SculptureViewModel.NewSculpture.C_SculptureID; sculpture.C_Name = SculptureViewModel.NewSculpture.C_Name; sculpture.C_Location = SculptureViewModel.NewSculpture.C_Location; SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture); //SculptureViewModel.NewSculpture.C_SculptureID = 0; //SculptureViewModel.NewSculpture.C_Name = ""; //SculptureViewModel.NewSculpture.C_Location = ""; }
public IHttpActionResult DeleteSculpture(int id) { Sculpture sculpture = db.Sculptures.Find(id); if (sculpture == null) { return(NotFound()); } db.Sculptures.Remove(sculpture); db.SaveChanges(); return(Ok(sculpture)); }
public void SelectSculpture(Sculpture sculpture) { foreach (Sculpture s in room.sculptures) { if (s.Equals(sculpture)) { s.SetSelected(!s.GetSelected()); } else if (s.GetSelected()) { s.SetSelected(false); } } }
public void MutateSculptures() { ArtGallery ag = ArtGallery.GetArtGallery(); //Sort Sculptures Sculpture[] toMutate = new Sculpture[sculptures.Length]; TWEANNGenotype sculptureChampion = null; for (int s = 0; s < sculptures.Length; s++) { if (sculptures[s].GetSelected()) { sculptureChampion = new TWEANNGenotype(sculptures[s].GetGenotype().Copy()); sculptures[s].SetSelected(false); toMutate[s] = sculptures[s]; } else { toMutate[s] = sculptures[s]; } } //Select sculpture champion and crossover / mutate if (sculptureChampion != null) { for (int m = 0; m < sculptures.Length; m++) { Sculpture ms = toMutate[m]; if (ms != null) { TWEANNGenotype crossedGeno = new TWEANNGenotype(sculptureChampion.Copy()); TWEANNCrossover cross = new TWEANNCrossover(false) { Sucessful = false }; // HACK PROTOTYPE hardcoded value //TWEANNGenotype crossedmgeno = cross.Crossover(new TWEANNGenotype(sculptureChampion.Copy()), new TWEANNGenotype(ms.GetGenotype().Copy())); //crossedGeno = crossedmgeno; for (int mr = 0; mr < Random.Range(2, ag.sculptureMutationChances); mr++) //HACK PROTOTYPE hardcoded value for mutation rate { crossedGeno.Mutate(); } ms.NewSculpture(new TWEANNGenotype(crossedGeno)); } } } }
/// <summary> /// Constructor for the initial room. invoked once per game /// </summary> /// <param name="numArtworks"></param> public RoomConfiguration(int numArtworks) { ArtArchetypeIndex = EvolutionaryHistory.NextPopulationIndex(); EvolutionaryHistory.archetypes[ArtArchetypeIndex] = new TWEANNGenotype(4, 3, ArtArchetypeIndex).Nodes; parentRoom = null; rooms = new RoomConfiguration[numArtworks]; artworks = new Artwork[numArtworks]; sculptures = new Sculpture[4]; // HACK PROTOTYPE hardcoded var. fix later for (int i = 0; i < numArtworks; i++) { artworks[i] = new Artwork(ArtArchetypeIndex); } //SetSculptures HAS to be called right after this constructor is called and initialized to create the lobby! this will change later }
// Create a new Sculpture private static void Exercise2() { Console.WriteLine("Exercise 2"); const string ServerUrl = "http://localhost:3285"; Console.WriteLine("Insert a new sculpture"); Console.Write("Enter number of new sculpture:"); int newSculpturelNo = int.Parse(Console.ReadLine()); var newSculture = new Sculpture("Marmaid", "København strand", "ground", "Granite", "building"); newSculture.Sculpture_Id = newSculpturelNo; string newSculptureJson = JsonConvert.SerializeObject(newSculture); var content = new StringContent(newSculptureJson, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsync("api/sculptures", content).Result; Console.WriteLine("PostAsync"); Console.WriteLine("Status code " + response.StatusCode); if (response.IsSuccessStatusCode) { var responseSculpture = client.GetAsync("api/sculptures/" + newSculpturelNo).Result; Console.WriteLine("GetAsync"); Console.WriteLine("Status code " + response.StatusCode); if (responseSculpture.IsSuccessStatusCode) { newSculture = responseSculpture.Content.ReadAsAsync <Sculpture>().Result; Console.WriteLine(newSculture.ToString()); var sculpture100 = responseSculpture.Content.ReadAsAsync <Sculpture>().Result; Console.WriteLine(sculpture100.ToString()); Console.WriteLine("SculptureNo {0},{1}", sculpture100.Sculpture_Id, sculpture100.Sculpture_Name); } Console.ReadLine(); } else { Console.WriteLine("Error: " + response.ReasonPhrase); //var errors = response.ModelState.Values.SelectMany(v => v.Errors); } } }
/// <summary> /// This method is called whenver the user creates a new sculpture. /// </summary> /// <param name="sculpture">This parameter holds all the information about the new created sculpture which is going to be inserted into the Database.</param> /// <returns></returns> public async Task CreateSculptureAsync(Sculpture sculpture) { using (var client = new HttpClient(_handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var json = JsonConvert.SerializeObject(sculpture); var sculptureContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); try { var response = await client.PostAsync("Api/Sculptures", sculptureContent); } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } } }
public async Task <ActionResult <Product> > update(int id, [FromBody] Sculpture incoming) { var product = dbContext.Products.Find(id); if (product != null) { product.LastUpdate = DateTime.Now; product.Width = incoming.Width; product.Name = incoming.Name; dbContext.SaveChanges(); return(get_product(id)); } else { ModelState.AddModelError("id", "Invalid client ID"); } return(BadRequest(ModelState)); }
public void SaveSculpture(Sculpture sculpture) { using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { string postBody = JsonConvert.SerializeObject(sculpture); var response = client.PostAsync("api/Sculptures", new StringContent(postBody, Encoding.UTF8, "application/json")) .Result; } catch (Exception ex) { new MessageDialog(ex.Message).ShowAsync(); // MessageDialog dialog = new MessageDialog(ex.Message); } } }
/// <summary> /// This method is called when a new sculpture is going to be created. /// </summary> /// <param name="sculpture">As for the update sculpture, we need also the sculpture object as a parameter.</param> public static async void CreateSculpture(Sculpture sculpture) { await new Persistancy.PersistenceFacade().CreateSculptureAsync(sculpture); var parameterList = new List <int>(); sculpture.SculptureMaterials.ForEach(material => parameterList.Add(material.ID)); await new Persistancy.PersistenceFacade().UpdateSculptureMaterialsAsync(sculpture.ID, parameterList); var parameterList2 = new List <string>(); sculpture.SculptureTypes.ForEach(type => parameterList2.Add(type)); parameterList.Clear(); parameterList2.ForEach(x => { switch (x) { case "Skulptur": parameterList.Add(1); break; case "Sokkel": parameterList.Add(2); break; case "Relief": parameterList.Add(3); break; case "Vandkunst": parameterList.Add(4); break; default: break; } }); await new Persistancy.PersistenceFacade().UpdateSculptureTypesAsync(sculpture.ID, parameterList); SculptureCatalogSingleton.Instance.Sculptures.Add(sculpture); await SculpturesHandler.ResetCollectionAsync(); }
public void UpdateSculpture() { Sculpture sculptureToUpdate = new Sculpture() { Sculpture_Id = SculptureViewModel.NewSculpture.Sculpture_Id, Sculpture_Name = SculptureViewModel.NewSculpture.Sculpture_Name, Sculpture_Adress = SculptureViewModel.NewSculpture.Sculpture_Adress, Sculpture_Placement = SculptureViewModel.NewSculpture.Sculpture_Placement, Material = SculptureViewModel.NewSculpture.Material, TypeLoc = SculptureViewModel.NewSculpture.TypeLoc }; new PersistenceFacade().UpdateSculpture(sculptureToUpdate); //Updated the ListView // SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture); var sculptures = new PersistenceFacade().GetSculptures(); SculptureViewModel.SculptureCatalogSingleton.Sculptures.Clear(); foreach (var sculpture1 in sculptures) { SculptureViewModel.SculptureCatalogSingleton.Sculptures.Add(sculpture1); } SculptureViewModel.NewSculpture = new Sculpture(); }
private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = new Ray(camera.transform.position, camera.transform.forward * interactionDistance); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; if (hit.collider.tag == "portal") { Portal p = hit.collider.gameObject.GetComponent <Portal>(); Texture2D img = new Texture2D(p.GetImage().width, p.GetImage().height, TextureFormat.ARGB32, false); Graphics.CopyTexture(p.GetImage(), img); int portalID = p.GetPortalID(); TWEANNGenotype geno = new TWEANNGenotype(ag.GetArtwork(portalID).GetGenotype().Copy()); SavedArtwork newArtwork = new SavedArtwork { Image = Sprite.Create(img, new Rect(0, 0, img.width, img.height), new Vector2(0.5f, 0.5f)) as Sprite, Geno = geno }; AddItem(newArtwork); FindNextEmptySlot(); } if (hit.collider.tag == "sculpture") { Sculpture s = hit.collider.gameObject.GetComponent <Sculpture>(); sculptureGeno = s.GetComponent <Sculpture>().GetGenotype(); ag.SelectSculpture(s); //s.GetComponent<Sculpture>().SetSelected(!s.GetComponent<Sculpture>().GetSelected()); } } } if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = new Ray(camera.transform.position, camera.transform.forward * interactionDistance); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; if (hit.collider.tag == "portal") { Portal p = hit.collider.gameObject.GetComponent <Portal>(); int portalID = p.GetPortalID(); Artwork art = ag.GetArtwork(portalID); if (GetActiveSlotItem() != null) { ag.RemoveRoom(portalID); art.SetGenotype(GetActiveSlotItem().Geno); // FIXME Null ref possible here - add checks art.Refresh(); art.ApplyImageProcess(); items[ActiveSlot] = null; hud.UpdateInventoryThumbnail(ActiveSlot, null); } else { // do nothing for now } } if (hit.collider.tag == "sculpture") { Sculpture s = hit.collider.gameObject.GetComponent <Sculpture>(); sculptureGeno = s.GetComponent <Sculpture>().GetGenotype(); ag.ResetSculpture(s); //s.GetComponent<Sculpture>().SetSelected(!s.GetComponent<Sculpture>().GetSelected()); } } } if (Input.GetKeyDown(KeyCode.Keypad4)) { CycleActiveSlot(-1); } if (Input.GetKeyDown(KeyCode.Keypad6)) { CycleActiveSlot(1); } float wheel = Input.GetAxis("Mouse ScrollWheel"); if (wheel < 0f) { //scroll down CycleActiveSlot(-1); } else if (wheel > 0f) { //scroll up CycleActiveSlot(1); } }
/// <summary> /// This method is called when the user wants to edit an existing sculpture. /// </summary> /// <param name="sculpture">In order to save the new details in the database we need the sculpture object as a parameter.</param> public static async void UpdateSculpture(Sculpture sculpture) { await new Persistancy.PersistenceFacade().UpdateSculptureAsync(sculpture); SculptureCatalogSingleton.Instance.Sculptures.RemoveAt(sculpture.ID); SculptureCatalogSingleton.Instance.Sculptures.Insert(sculpture.ID, sculpture); }
public void ResetSculpture(Sculpture s) { s.NewSculpture(); }
public CreateSculptureViewModel() { NewSculpture = new Sculpture(SculptureCatalogSingleton.Instance.Sculptures.Count + 1); }