protected void btnAddCatalogItem_Click(object sender, EventArgs e) { Boolean fileOK = false; String path = Server.MapPath("~/Catalog/Images/"); if (ObjectImage.HasFile) { String fileExtension = System.IO.Path.GetExtension(ObjectImage.FileName).ToLower(); String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { try { // Save to Images folder. ObjectImage.PostedFile.SaveAs(path + ObjectImage.FileName); // Save to Images/Thumbs folder. ObjectImage.PostedFile.SaveAs(path + "Thumbs/" + ObjectImage.FileName); } catch (Exception ex) { LabelAddStatus.Text = ex.Message; } // Add the item to the Catalog Table. AddObjects catalogObjects = new AddObjects(); bool addSuccess = catalogObjects.AddObject(AddObjectName.Text, AddItemDescription.Text, AddCatalogObjectPrice.Text, DropDownAddCategory.SelectedValue, ObjectImage.FileName); if (addSuccess) { // Reload the page. string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); Response.Redirect(pageUrl + "?CatalogObjectAction=add"); } else { LabelAddStatus.Text = "Unable to add new item to database."; } } else { LabelAddStatus.Text = "Unable to accept file type."; } }
// Создать изменения для добавления сущностей на поле private IList <StateChange> CreateNewEntitiesChanges(ChangeData data) { // Создать один объект из его данных GameObject createEntityFromData(ChangeData objData) { string type = objData["name"] as string; string id = objData["id"] as string; var newEntity = session.ResourceManager.CreateObject(type, id); newEntity.LayoutId = objData["layout"] as string; newEntity.Position = ConvertCoordsToVector(objData["position"]); newEntity.Rotation = ConvertCoordsToVector(objData["rotation"]); return(newEntity); } // Создать несколько объектов, либо один var newEntities = new List <GameObject>(); if (data.ContainsKey("entities") && data["entities"] is object[] defs) { foreach (var entityDef in defs) { newEntities.Add(createEntityFromData(entityDef as ChangeData)); } } else { newEntities.Add(createEntityFromData(data)); } var message = new AddObjects(newEntities); return(new StateChange[] { CreateChange(message, data) }); }
public QnAMakerUpdateKBInput() { Add = new AddObjects(); Update = new UpdateObjects(); }