public ActionResult Edit(string id) { Good good = new Good(); GoodViewModel goodViewModel = new GoodViewModel(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } good = _goodRepository.Get(x => x.Id == id).FirstOrDefault(); if (good == null) { return(HttpNotFound()); } goodViewModel.GoodId = good.Id; goodViewModel.Name = good.Name; goodViewModel.Price = good.Price; goodViewModel.ManufacturerId = good.ManufacturerId; goodViewModel.Amount = good.Amount; goodViewModel.TypeId = good.TypeId; goodViewModel.Description = good.Description; goodViewModel.ManufacturerVM = _manufacturerRepository.Get(); goodViewModel.TypeVM = _typeRepository.Get(); return(View(goodViewModel)); }
public void Get() { //Act var result = repository.Get(id); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(Type)); Assert.AreEqual(id, result.ID); }
public void Serialize(object value) { if (value == null) { return; } var info = TypeRepository.Get(value.GetType()); if (info.IsSimple) { Pack(value); return; } if (info.IsArray) { var array = (IList)value; Pack(array.Count); foreach (var item in array) { Serialize(item); } return; } if (info.IsChild) { Pack(info.Discriminator.Value); } var accessor = info.GetAccessor(value); var flags = 0u; var i = 1u; foreach (var f in info.Fields) { var x = accessor.Get(f.Index); if (x != null) { flags |= i; } i <<= 1; } Pack(flags); foreach (var f in info.Fields) { var x = accessor.Get(f.Index); Serialize(x); } }
public override RecordTypeInfo GetType(int discriminator) { switch ((UnitType)discriminator) { case UnitType.Fighter: return(TypeRepository.Get(typeof(Fighter))); case UnitType.Mage: return(TypeRepository.Get(typeof(Mage))); case UnitType.Thief: return(TypeRepository.Get(typeof(Thief))); default: return(null); // throw } }
public void Serialize(object value) { if (value == null) { return; } var info = TypeRepository.Get(value.GetType()); if (info.IsSimple) { _s.WriteLine(value.ToString()); return; } if (info.IsArray) { var array = (IList)value; _s.WriteLine(array.Count); foreach (var item in array) { Serialize(item); } return; } if (info.IsChild) { _s.WriteLine(info.Discriminator.Value); } var accessor = info.GetAccessor(value); foreach (var f in info.Fields) { _s.WriteLine(f.Name); var x = accessor.Get(f.Index); Serialize(x); } }
public IEnumerable <EntityType> Get() => _repository.Get();
public void GetType_InexistentType_ShouldReturnNull() { Type typeById = typeRepositoryInMemory.Get(brokenContainer.Id); Assert.IsNull(typeById); }
public object Deserialize(Type t) { if (t.IsPrimitive) { if (t == typeof(int)) { return((int)UnpackNumber()); } if (t == typeof(double)) { return((double)UnpackNumber()); } if (t == typeof(bool)) { return((bool)UnpackNumber()); } if (t == typeof(long)) { return((long)UnpackNumber()); } if (t == typeof(byte)) { return((byte)UnpackNumber()); } if (t == typeof(sbyte)) { return((sbyte)UnpackNumber()); } if (t == typeof(short)) { return((short)UnpackNumber()); } if (t == typeof(ushort)) { return((ushort)UnpackNumber()); } if (t == typeof(uint)) { return((uint)UnpackNumber()); } if (t == typeof(ulong)) { return((ulong)UnpackNumber()); } if (t == typeof(float)) { return((float)UnpackNumber()); } } else if (t == typeof(string)) { return(UnpackString()); } var info = TypeRepository.Get(t); if (info.IsArray) { var length = (int)UnpackNumber(); var array = info.GetArray(length); var elem = ((ArrayTypeInfo)info).ElementType.Type; for (int i = 0; i < length; i++) { var item = Deserialize(elem); array.SetValue(item, i); } return(array); } if (info.IsBase) { var discriminator = (int)UnpackNumber(); info = info.GetType(discriminator); } var value = info.GetInstance(); var accessor = info.GetAccessor(value); var count = info.Fields.Count(); var flags = (uint)UnpackNumber(); foreach (var field in info.Fields) { if ((flags & 1) == 0) { continue; } flags >>= 1; var x = Deserialize(field.Type.Type); accessor.Set(field.Index, x); } return(value); }
public object Deserialize(Type t) { if (t == typeof(int)) { return(int.Parse(_s.ReadLine())); } if (t == typeof(double)) { return(double.Parse(_s.ReadLine())); } if (t == typeof(string)) { return(_s.ReadLine()); } var info = TypeRepository.Get(t); if (info.IsArray) { var length = int.Parse(_s.ReadLine()); var array = info.GetArray(length); var elem = ((ArrayTypeInfo)info).ElementType.Type; for (int i = 0; i < length; i++) { var item = Deserialize(elem); array.SetValue(item, i); } return(array); } if (info.IsBase) { var line = _s.ReadLine(); var discriminator = int.Parse(line); info = info.GetType(discriminator); } var value = info.GetInstance(); var accessor = info.GetAccessor(value); var count = info.Fields.Count(); while (true) { var line = _s.ReadLine(); if (line == null) { break; } var field = info.Fields.First(f => f.Name == line); var x = Deserialize(field.Type.Type); accessor.Set(field.Index, x); --count; if (count == 0) { break; } } return(value); }