public void TestAdd() { var dbConnection = AppConfigConnectionFactory.CreateSicConnection(); //using (dbConnection.BeginTransaction()) { var sut = new ConfigRepository(dbConnection); var expected = new LomoConfig { Name = "MyConfig", Description = "Description", Customer = new Customer("John", 0), Fields = new Collection<Field> { new Field {Name = "Test1", Description = "Description1"}, new Field {Name = "Test2", Description = "Description2"}, } }; var id = sut.Create(expected); expected.Id = id; var actual = sut.Get(id); Assert.Equal(expected, actual); } }
public void Update(LomoConfig lomoConfig) { var toReplace = LomoConfigs.Single(config => config.Id == lomoConfig.Id); var id = lomoConfigs.IndexOf(toReplace); if (id != -1) { lomoConfigs.RemoveAt(id); lomoConfigs.Insert(id, lomoConfig); } }
public int Add(LomoConfig lomoConfig) { if (lomoConfig.Id.HasValue) { throw new InvalidOperationException("The entity should not explicitly choose its Id. It should be set to null."); } var newId = GenerateNewId(); lomoConfigs.Add(lomoConfig); lomoConfig.Id = newId; return newId; }
public static LomoConfig Convert(LomoConfigViewModel lomoConfigViewModel) { var converted = new LomoConfig { Id = lomoConfigViewModel.Id, BoxCount = lomoConfigViewModel.BoxCount.DataValue.Value, Customer = Convert(lomoConfigViewModel.SelectedCustomer.DataValue), Description = lomoConfigViewModel.Description.DataValue, ImagePath = lomoConfigViewModel.ImagePath.DataValue, Name = lomoConfigViewModel.Name.DataValue }; return converted; }
public static LomoConfigViewModel Convert(LomoConfig lomoConfig, ICustomerRepository customerRepository, IOpenFileService openFileService) { var viewModel = new LomoConfigViewModel(lomoConfig.Name, openFileService, customerRepository) { Id = lomoConfig.Id, BoxCount = { DataValue = lomoConfig.BoxCount }, SelectedCustomer = { DataValue = lomoConfig.Customer != null ? Convert(lomoConfig.Customer) : null }, Description = { DataValue = lomoConfig.Description }, ImagePath = { DataValue = lomoConfig.ImagePath }, Fields = new ObservableCollection<FieldViewModel>(lomoConfig.Fields.Select(Convert)), }; return viewModel; }
public void Update() { var sut = new InMemoryLomoConfigService(); var id = sut.Add(new LomoConfig()); var expected = new LomoConfig { Name = "New", Id = id }; sut.Update(expected); var actual = sut.Get(id); Assert.Equal(expected, actual); }
private LomoConfig MapFromReader(IDataRecord record) { var id = (int) (decimal) record["TOCRID"]; var entity = new LomoConfig { Id = id, Name = record.GetValue<string>("TOCRDOCNOMBRE"), Description = record.GetValue<string>("TOCRDESC"), ImagePath = record.GetValue<string>("TOCREXFILE"), CropLeft = record.GetValue<decimal>("TOCRORX"), CropTop = record.GetValue<decimal>("TOCRORY"), CropWidth = record.GetValue<decimal>("TOCRDX"), CropHeight = record.GetValue<decimal>("TOCRDY"), Rotation = record.GetValue<decimal>("TOCRROTACIONINICIAL"), BoxCount = (int) record.GetValue<decimal>("TOCRCAJAS"), Fields = GetFields(id), }; var customerName = record.GetValue<string>("TOCRCLIENTE"); entity.Customer = customerName == null ? null : new Customer(customerName, null); return entity; }
public void Update(LomoConfig newLomoConfig) { throw new System.NotImplementedException(); }
public int Create(LomoConfig lomoConfig) { using (var tr = connection.BeginTransaction()) { var id = GetNextId(); using (var command = connection.CreateCommand()) { command.CommandText = @"INSERT INTO TIPOSOCR (TOCRDOCNOMBRE, TOCRDESC, TOCREXFILE, TOCRCLIENTE, TOCRCAJAS) VALUES(:TOCRDOCNOMBRE, :TOCRDESC, :TOCREXFILE, :TOCRCLIENTE, :TOCRCAJAS)"; command.AddParameter("TOCRDOCNOMBRE", lomoConfig.Name); command.AddParameter("TOCRDESC", lomoConfig.Description); command.AddParameter("TOCREXFILE", lomoConfig.ImagePath); command.AddParameter("TOCRCLIENTE", lomoConfig.Customer.Name); command.AddParameter("TOCRCAJAS", lomoConfig.BoxCount); command.ExecuteNonQuery(); } foreach (var field in lomoConfig.Fields) { CreateFieldsForConfig(connection, field, id+1); } tr.Commit(); return id+1; } }