public async Task <ValueModel?> Update(ValueModel model) { var value = await _repository.Update(model); _logger.LogDebug("Updated value {@value}", value); return(value); }
public override void Bind(TradeViewModel model) { base.Bind(model); Available?.Bind(model.Available); Mine?.Bind(model.Mine); Port?.Bind(ValueModel.New(new ButtonViewModel { Label = "Port", OnClick = model.BackToPort })); Monuments?.Bind(ValueModel.New(new ButtonViewModel { Label = "Monuments", OnClick = () => Globals.UI.Show <ShrinesView, ShrinesViewModel>(new ShrinesViewModel()) })); Info?.Bind(ValueModel.New(new ButtonViewModel { OnClick = () => Globals.UI.Show <InfoScreen, InfoScreenModel>(new InfoScreenModel { Icon = model.PortCoin, Title = model.PortName, Subtitle = model.PortPopulationRank, Message = model.PortDescription }) })); Money.Bind(ValueModel.Wrap(Model.Money) .AsString() .Select(s => s + " dr") ); BuiltMonuments.Bind(new BoundModel <string>(Model.Ship, nameof(Model.Ship.builtMonuments))); }
public object Assemble(ValueModel model, Type expectedType, AssemblyContext context) { IAssemblable serializable = Activator.CreateInstance(expectedType) as IAssemblable; serializable.Assemble(model, context); return(serializable); }
public async Task LockFailTest() { var etagOriginal = this.rand.NextString(); var model = new ValueModel { Value = this.rand.NextString() }; model.Locked = true; var dataOriginal = JsonConvert.SerializeObject(model); var @lock = new StorageWriteLock <ValueModel>( this.mockClient.Object, COLL, KEY, (v, b) => v.Locked = b, m => !JsonConvert.DeserializeObject <ValueModel>(m.Data).Locked); this.mockClient .Setup(x => x.GetAsync( It.Is <string>(s => s == COLL), It.Is <string>(s => s == KEY))) .ReturnsAsync(new ValueApiModel { Data = dataOriginal, ETag = etagOriginal }); var result = await @lock.TryLockAsync(); Assert.False(result.Value); }
public void DeserializeProgress(ValueModel source) { if (!ValueModel.IsNull(source)) { Requirement?.DeserializeProgress(source); } }
// PUT: api/Value/5 public void Put(int id, [FromBody] ValueModel value) { if (id < _list.Count) { _list[id] = value.Text; } }
public Task <ValueEntity> Create(ValueModel value) => Task.FromResult(new ValueEntity { Id = 10, Name = value.Name, Value = value.Value });
// GET api/values public async Task <IEnumerable <ValueModel> > Get() { List <ValueModel> retVal = new List <ValueModel>(); string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["AuthTest"].ConnectionString; using (SqlConnection connection = new SqlConnection(connStr)) { await connection.OpenAsync(); using (SqlCommand command = new SqlCommand("SELECT Id, [Value], USER_NAME() FROM [VALUES]", connection)) using (SqlDataReader dataReader = await command.ExecuteReaderAsync()) { while (await dataReader.ReadAsync()) { ValueModel val = new ValueModel(); val.Id = dataReader.GetInt32(0); val.Value = dataReader.GetString(1); val.CurrentUser = dataReader.GetString(2); retVal.Add(val); } } } return(retVal); }
public object Assemble(ValueModel model, Type expectedType, AssemblyContext context) { ArrayModel array = model as ArrayModel; Type elementType = GetElementType(expectedType); bool isList = IsList(expectedType); object list = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)); MethodInfo add = list.GetType().GetMethod("Add"); // I barfed a little writing that. for (int i = 0; i < array.Length; i++) { add.Invoke(list, new object[] { _elementAssembler.Assemble(array[i], array.IsTypeImplicit ? elementType : array[i].GetModelType(), context) }); } if (isList) { return(list); } else { MethodInfo toArray = list.GetType().GetMethod("ToArray"); return(toArray.Invoke(list, new object[] { })); } }
public async Task <IActionResult> AddValue([FromBody] ValueModel value) { _context.Values.Add(value); await _context.SaveChangesAsync(); return(Ok(value)); }
public JToken Serialize(ValueModel value) { Type valueType = value == null ? typeof(NullModel) : value.GetType(); var strat = GetSerializerStrategy(valueType); return(strat == null?JValue.CreateNull() : strat.Serialize(value)); }
public void Assemble(ValueModel source, AssemblyContext context) { ObjectModel obj = source as ObjectModel; TierIndex = obj.GetValue <int>("Tier"); VariantIndex = obj.GetValue <int>("Variant"); }
public async Task <IEnumerable <ValueModel> > Get() { _logger.LogInformation("I am here"); List <ValueModel> retVal = new List <ValueModel>(); string connStr = configuration.ConnectionStrings.AuthTest; using (SqlConnection connection = new SqlConnection(connStr)) { connection.AccessToken = await(new AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/"); await connection.OpenAsync(); using (SqlCommand command = new SqlCommand("SELECT Id, [Value], USER_NAME() FROM [VALUES]", connection)) using (SqlDataReader dataReader = await command.ExecuteReaderAsync()) { while (await dataReader.ReadAsync()) { ValueModel val = new ValueModel(); val.Id = dataReader.GetInt32(0); val.Value = dataReader.GetString(1); val.CurrentUser = dataReader.GetString(2); retVal.Add(val); } } } return(retVal); }
public async Task <IActionResult> GetAsync(int?id) { try { if (id == null) { throw new ArgumentException($"Parameter {nameof(id)} cannot be null", nameof(id)); } var value = await _valueService.GetValueAsync(id.Value); if (value == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } var valueModel = new ValueModel(value); return(Ok(valueModel)); } catch (ArgumentException argumentException) { return(StatusCode((int)HttpStatusCode.BadRequest, argumentException.Message)); } catch (Exception exception) { return(StatusCode((int)HttpStatusCode.InternalServerError, exception.Message)); } }
public async Task <ActionResult> Post([FromRoute, Required] string key, [FromBody, Required] ValueModel model) { var value = Convert.FromBase64String(model.DataBase64); await _dataProvider.WriteAsync(Encoding.UTF8.GetString(value), key); return(NoContent()); }
protected override void Refresh(object sender, string propertyChanged) { base.Refresh(sender, propertyChanged); //If the ship is at 100HP already, then let's not worry about giving the player the costs--we'll replace the costs by an X // --and disable the repair buttons if (Mathf.CeilToInt(Model.shipHealth.Value) == 100) { CostOneHp.Bind(ValueModel.New("X")); CostAllHp.Bind(ValueModel.New("X")); RepairOneButton.GetComponent <Button>().interactable = false; RepairAllButton.GetComponent <Button>().interactable = false; } else { CostOneHp.Bind(ValueModel.New(Model.costToRepair) .Select(cost => Mathf.CeilToInt(cost)) .AsString()); CostAllHp.Bind(ValueModel.New(Model.costToRepair) .Select(cost => (Mathf.CeilToInt(100 - Mathf.CeilToInt(Globals.GameVars.playerShipVariables.ship.health)) * cost)) .AsString()); RepairOneButton.GetComponent <Button>().interactable = true; RepairAllButton.GetComponent <Button>().interactable = true; } // TODO: Flesh out upgrade system? For now, you can only upgrade once and it just gives you the main ship. You start out with a smaller one. UpgradeButton.GetComponent <Button>().interactable = Model.shipLevel.Value == 0; }
} // New Value Method public IHttpActionResult Put(int id, ValueModel Value) { try { if (Value == null) { return(BadRequest("Could not read Value from body")); } var originalValue = _ctx.Values.Find(id); if (originalValue == null || originalValue.ID != id) { return(BadRequest("Value is not found")); } else { Value.ID = id; } _ctx.Entry(originalValue).CurrentValues.SetValues(Value); _ctx.SaveChanges(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } } // Update Value Method
protected override JToken SerializeWithoutMetadata(ValueModel value) { ObjectModel model = value as ObjectModel; IEnumerable <JProperty> properties = model.GetProperties().Select(x => new JProperty(x.Name, _internalSerializer.Serialize(x.Model))); return(new JObject(properties)); }
public override void DeserializeProgress(ValueModel model) { if (!ValueModel.IsNull(model)) { _enemiesSlain = (model as PrimitiveModel).ToObject <int>(); } }
public async Task <ValueModel?> Create(ValueModel valueModel) { var value = await _repository.Create(valueModel); _logger.LogDebug("Created value {@value}", value); return(value); }
public ConfirmCol3Form(ValueModel ValueModel, ObsConvTool obsConvTool) { InitializeComponent(); this.ValueModel = ValueModel; this.ObsConvTool = obsConvTool; this.StartId = 0; }
public static void Save(ValueModel model) { Log.WriteEnter(typeof(ValueService).FullName, MethodBase.GetCurrentMethod().Name); var dataModel = XmlDal.DataModel; switch (model.Mode) { case InputMode.Add: model.Item.ValueId = XmlDal.DataModel.GetUniqueValueId(); dataModel.ValuesModel.Values.Add(model.Item); break; case InputMode.Edit: var item = dataModel.GetValue(model.Item.ValueId); item.Copy(model.Item); break; case InputMode.Delete: dataModel.ValuesModel.Values.Remove(model.Item); break; } XmlDal.Save(); XmlDal.DataModel.ValueCacheDataController.Invalidate(); }
private TileTypeReference DeserializeTileTypeReference(ValueModel model, AssemblyContext context) { TileTypeReference reference = new TileTypeReference(); reference.Assemble(model, context); return(reference); }
private StringContent SerializeToString(ValueModel valueModel) { return(new StringContent( JsonConvert.SerializeObject(valueModel), UnicodeEncoding.UTF8, "application/json" )); }
private async Task PostValueModel(ValueModel valueModel) { var stringContent = SerializeToString(valueModel); var postMessage = await _testClient.PostAsync("/api/values", stringContent); postMessage.EnsureSuccessStatusCode(); }
public static Data.Entities.ValueEntity ConvertToEntity(this ValueModel input) { return(new Data.Entities.ValueEntity { Id = input.Id, Value = input.Value }); }
public ObsConvTool() { InitializeComponent(); ValueModel = new ValueModel(); SdrTable = new DataTable(); SdrText = ""; MacText = ""; }
public override void Bind(ICollectionModel <CargoInventoryViewModel> model) { base.Bind(model); CloseButton?.Bind(ValueModel.New(new ButtonViewModel { OnClick = () => Globals.UI.Hide(this) })); }
public IActionResult Post([FromBody] ValueModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(new ObjectResult(value)); }
public object Assemble(ValueModel model, Type expectedType, AssemblyContext context) { Type type = model.IsTypeImplicit ? expectedType : model.GetModelType(); object obj = CreateInstance(type); _populator.Populate(obj, model as ObjectModel, context); return(obj); }
/// <summary> /// Sends value to DAL. /// </summary> /// <param name="model">What to save.</param> /// <returns>If operation commited succesfully.</returns> internal static bool Save(ValueModel model) { Modifier modifier = new Modifier(); return modifier.Modify(model.DalValue); }
public ActionResult AjaxValueOperation(int id, Object Value) { if(!HttpContext.Request.IsAjaxRequest()) { return Badrequest(); } try { ValueModel model; ProjectsReader dal = new ProjectsReader(); IValue original = dal.GetValue(id); HttpContextWarker contexter = new HttpContextWarker(HttpContext); bool canModify = contexter.CanModify(original.GetProject()); if (contexter.Method.Equals(HttpVerbs.Post)) { original.SetValue(Value); original.Author = contexter.User.Name; original.Time = DateTime.Now; model = new ValueModel(original, canModify); if(!canModify) { throw new NotEnoughRightsException(ResourcesHelper.GetText("OnNotEnoughForModifyingValue", contexter.GetCulture())); } if(!ProjectHelper.Save(model)) { throw new InvalidUserInputException(); } } else { model = new ValueModel(original, canModify); } return PartialView("JustLookValue", model); } catch(ProjectWatcher.Errors.ProjectWatcherException e) { return Json(new {error = e.Message}, JsonRequestBehavior.AllowGet); } }
public PartialViewResult EditValue(Int32 id) { ProjectsReader reader = new ProjectsReader(); IValue value = reader.GetValue(id); IProject project = reader.GetProject(value.ProjectId); HttpContextWarker contexter = new HttpContextWarker(HttpContext); if(!contexter.CanModify(project)) { throw new NotEnoughRightsException(); } ValueModel model = new ValueModel(reader.GetValue(id), true); ViewData["culture"] = contexter.GetCulture(); return PartialView("ValueEdit", model); }