public async Task insert_where_key_is_string_using_Insert_should_return_true() { var ticket = new Ticket("insert customer demographics"); var customerDemographic = new CustomerDemographic { CustomerTypeId = "Potential", CustomerDescription = "Potential customers" }; string sql = null; IDictionary <string, object> parameters = null; Jaunty.OnInserting += (sender, args) => { sql = args.Sql; parameters = args.Parameters; }; northwind.Connection.Delete <CustomerDemographic, string>(customerDemographic.CustomerTypeId); bool success = await northwind.Connection.InsertAsync(customerDemographic, ticket : ticket); Assert.Equal("INSERT INTO CustomerDemographics (CustomerTypeId, CustomerDescription) " + "VALUES (@CustomerTypeId, @CustomerDescription);", sql); Assert.NotEmpty(parameters); Assert.Equal("CustomerTypeId", parameters.ElementAt(0).Key); Assert.Equal("Potential", parameters.ElementAt(0).Value); Assert.Equal("CustomerDescription", parameters.ElementAt(1).Key); Assert.Equal("Potential customers", parameters.ElementAt(1).Value); Assert.True(success); }
public IEnumerable <ModelValidationResult> Validate(ModelValidationContext context) { IEnumerable <ModelValidationResult> result = Enumerable.Empty <ModelValidationResult>(); // Dependancy injection does not work with attributes so manually wire up the database context. using (NorthwindContext dbContext = DAL.Startup.NorthwindContext) { IRepository <CustomerDemographic, string> repository = new CustomerDemographicRepository(dbContext); string value = context.Model as string; if (value == null) { result = new List <ModelValidationResult>() { new ModelValidationResult("", "A customer type id must be provided") }; } else { CustomerDemographic model = repository.Fetch(value); if (model == null) { result = new List <ModelValidationResult>() { new ModelValidationResult("", ErrorMessage) }; } } } return(result); }
public async Task <IActionResult> Edit(string id, [Bind("CustomerTypeId,CustomerDesc")] CustomerDemographic customerDemographic) { if (id != customerDemographic.CustomerTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customerDemographic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerDemographicExists(customerDemographic.CustomerTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customerDemographic)); }
public IHttpActionResult PutCustomerDemographic(string id, CustomerDemographic customerDemographic) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customerDemographic.CustomerTypeID) { return(BadRequest()); } db.Entry(customerDemographic).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerDemographicExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void InsertUsingStringKey() { var guid = Guid.NewGuid(); var customerDemographic = new CustomerDemographic { CustomerTypeId = "Potential", CustomerDesc = "Potential customers" }; string sql = null; IDictionary <string, object> parameters = null; Speedy.OnInserting += (sender, args) => { if (((Guid)sender).Equals(guid)) { sql = args.Sql; parameters = args.Parameters; } }; connection.Delete <CustomerDemographic, string>(customerDemographic.CustomerTypeId); bool success = connection.Insert(customerDemographic, token: guid); Assert.Equal("INSERT INTO CustomerDemographics (CustomerTypeId, CustomerDesc) " + "VALUES (@CustomerTypeId, @CustomerDesc);", sql); Assert.NotEmpty(parameters); Assert.Equal("CustomerTypeId", parameters.ElementAt(0).Key); Assert.Equal("Potential", parameters.ElementAt(0).Value); Assert.Equal("CustomerDesc", parameters.ElementAt(1).Key); Assert.Equal("Potential customers", parameters.ElementAt(1).Value); Assert.True(success); }
public IHttpActionResult PostCustomerDemographic(CustomerDemographic customerDemographic) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CustomerDemographics.Add(customerDemographic); try { db.SaveChanges(); } catch (DbUpdateException) { if (CustomerDemographicExists(customerDemographic.CustomerTypeID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = customerDemographic.CustomerTypeID }, customerDemographic)); }
public static CustomerDemographic ToDto(this CustomerDemographicEntity entity, Hashtable seenObjects, Hashtable parents) { OnBeforeEntityToDto(entity, seenObjects, parents); var dto = new CustomerDemographic(); if (entity != null) { if (seenObjects == null) { seenObjects = new Hashtable(); } seenObjects[entity] = dto; parents = new Hashtable(parents) { { entity, null } }; // Map dto properties dto.CustomerTypeId = entity.CustomerTypeId; dto.CustomerDesc = entity.CustomerDesc; // Map dto associations // 1:n CustomerCustomerDemos association of CustomerCustomerDemo entities if (entity.CustomerCustomerDemos != null && entity.CustomerCustomerDemos.Any()) { dto.CustomerCustomerDemos = new CustomerCustomerDemoCollection(entity.CustomerCustomerDemos.RelatedArray(seenObjects, parents)); } } OnAfterEntityToDto(entity, seenObjects, parents, dto); return(dto); }
public CreateCustomerDemographicResponse CreateCustomerDemographic(CreateCustomerDemographicRequest request) { CreateCustomerDemographicResponse response = new CreateCustomerDemographicResponse(); CustomerDemographic customerDemographic = new CustomerDemographic(); customerDemographic.CustomerDesc = request.CustomerDesc; customerDemographic.Customers = request.Customers.ConvertToCustomers(); if (customerDemographic.GetBrokenRules().Count() > 0) { response.Errors = customerDemographic.GetBrokenRules().ToList(); } else { try { _customerDemographicRepository.Add(customerDemographic); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { List <BusinessRule> errors = new List <BusinessRule>(); do { errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); ex = ex.InnerException; } while (ex != null); response.Errors = errors; } } return(response); }
public ModifyCustomerDemographicResponse ModifyCustomerDemographic(ModifyCustomerDemographicRequest request) { ModifyCustomerDemographicResponse response = new ModifyCustomerDemographicResponse(); CustomerDemographic customerDemographic = _customerDemographicRepository .FindBy(request.CustomerTypeID); customerDemographic.Id = request.CustomerTypeID; customerDemographic.CustomerDesc = request.CustomerDesc; customerDemographic.Customers = request.Customers.ConvertToCustomers(); if (customerDemographic.GetBrokenRules().Count() > 0) { response.Errors = customerDemographic.GetBrokenRules().ToList(); } else { try { _customerDemographicRepository.Save(customerDemographic); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { response.Errors = new List <BusinessRule>(); response.Errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); } } return(response); }
public ActionResult DeleteConfirmed(string id) { CustomerDemographic customerDemographic = db.CustomerDemographics.Find(id); db.CustomerDemographics.Remove(customerDemographic); db.SaveChanges(); return(RedirectToAction("Index")); }
protected async void Load() { canEdit = true; var northwindGetCustomerDemographicByCustomerTypeIdResult = await Northwind.GetCustomerDemographicByCustomerTypeId($"{CustomerTypeID}"); customerdemographic = northwindGetCustomerDemographicByCustomerTypeIdResult; }
public CustomerDemographicDto Create(CustomerDemographic customerDemographic) { return(new CustomerDemographicDto { CustomerDesc = customerDemographic.CustomerDesc, CustomerTypeId = customerDemographic.CustomerTypeId }); }
internal void create(CustomerDemographic entity, NorthwindContext context) { string id = createId(); entity.CustomerTypeId = id; context.Add(entity); context.SaveChangesAsync(); }
public async Task <ActionResult> DeleteConfirmed(string id) { CustomerDemographic customerDemographic = await db.CustomerDemographics.FindAsync(id); db.CustomerDemographics.Remove(customerDemographic); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IActionResult Create([Bind("CustomerDesc")] CustomerDemographic customerDemographic) { if (ModelState.IsValid) { customerDemographicService.create(customerDemographic, _context); return(RedirectToAction(nameof(Index))); } return(View(customerDemographic)); }
protected async void GridDeleteButtonClick(UIMouseEventArgs args, CustomerDemographic data) { var northwindDeleteCustomerDemographicResult = await Northwind.DeleteCustomerDemographic($"{data.CustomerTypeID}"); if (northwindDeleteCustomerDemographicResult != null) { grid0.Reload(); } }
public void batchCreate(List <Customer> entities, CustomerDemographic demographic, NorthwindContext context) { entities.ForEach(x => x.CustomerId = createId()); List <CustomerCustomerDemo> lists = entities.Select(x => new CustomerCustomerDemo(x.CustomerId, demographic.CustomerTypeId)).ToList(); context.Customers.AddRange(entities); context.CustomerCustomerDemos.AddRange(lists); context.SaveChanges(); }
public ActionResult Edit([Bind(Include = "CustomerTypeID,CustomerDesc")] CustomerDemographic customerDemographic) { if (ModelState.IsValid) { db.Entry(customerDemographic).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerDemographic)); }
public virtual bool Equals(CustomerDemographic other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; if (CustomerTypeId != default(string)) { return other.CustomerTypeId == CustomerTypeId; } return other.CustomerTypeId == CustomerTypeId && other.CustomerDesc == CustomerDesc; }
public ActionResult Create([Bind(Include = "CustomerTypeID,CustomerDesc")] CustomerDemographic customerDemographic) { if (ModelState.IsValid) { db.CustomerDemographics.Add(customerDemographic); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerDemographic)); }
public async Task <IActionResult> Create([Bind("CustomerTypeId,CustomerDesc")] CustomerDemographic customerDemographic) { if (ModelState.IsValid) { _context.Add(customerDemographic); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customerDemographic)); }
public void InsertCustomerDemographic(CustomerDemographic customerDemographic) { if ((customerDemographic.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(customerDemographic, EntityState.Added); } else { this.ObjectContext.CustomerDemographics.AddObject(customerDemographic); } }
public IHttpActionResult GetCustomerDemographic(string id) { CustomerDemographic customerDemographic = db.CustomerDemographics.Find(id); if (customerDemographic == null) { return(NotFound()); } return(Ok(customerDemographic)); }
public void DeleteCustomerDemographic(CustomerDemographic customerDemographic) { if ((customerDemographic.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(customerDemographic, EntityState.Deleted); } else { this.ObjectContext.CustomerDemographics.Attach(customerDemographic); this.ObjectContext.CustomerDemographics.DeleteObject(customerDemographic); } }
public async Task <CustomerDemographic> CreateCustomerDemographic(CustomerDemographic customerDemographic) { try { context.CustomerDemographics.Add(customerDemographic); context.SaveChanges(); } catch (Exception ex) { return(null); } return(customerDemographic); }
public void InsertCustomerDemographic(CustomerDemographic customerDemographic) { DbEntityEntry <CustomerDemographic> entityEntry = this.DbContext.Entry(customerDemographic); if ((entityEntry.State != EntityState.Detached)) { entityEntry.State = EntityState.Added; } else { this.DbContext.CustomerDemographics.Add(customerDemographic); } }
// GET: CustomerDemographics/Delete/5 public async Task <ActionResult> Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustomerDemographic customerDemographic = await db.CustomerDemographics.FindAsync(id); if (customerDemographic == null) { return(HttpNotFound()); } return(View(customerDemographic)); }
public async Task<CustomerDemographic> CreateCustomerDemographic(CustomerDemographic customerDemographic) { var uri = new Uri(baseUri, $"CustomerDemographics"); var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri); httpRequestMessage.Content = new StringContent(ODataJsonSerializer.Serialize(customerDemographic), Encoding.UTF8, "application/json"); OnCreateCustomerDemographic(httpRequestMessage); var response = await httpClient.SendAsync(httpRequestMessage); return await response.ReadAsync<CustomerDemographic>(); }
public IActionResult CreateDemographic([Bind("CustomerDesc")] CustomerDemographic customerDemographic, MultipleInputCustomersAndDemographics aaa) { if (ModelState.IsValid) { aaa.multipleDemographics.newDemographics.Add(customerDemographic); aaa.multipleDemographics.newDemographic = null; return(View(nameof(Index), aaa)); } else { aaa.multipleDemographics.newDemographic = customerDemographic; } return(View(nameof(Index), aaa)); }
public void DeleteCustomerDemographic(CustomerDemographic customerDemographic) { DbEntityEntry <CustomerDemographic> entityEntry = this.DbContext.Entry(customerDemographic); if ((entityEntry.State != EntityState.Deleted)) { entityEntry.State = EntityState.Deleted; } else { this.DbContext.CustomerDemographics.Attach(customerDemographic); this.DbContext.CustomerDemographics.Remove(customerDemographic); } }
public IHttpActionResult DeleteCustomerDemographic(string id) { CustomerDemographic customerDemographic = db.CustomerDemographics.Find(id); if (customerDemographic == null) { return(NotFound()); } db.CustomerDemographics.Remove(customerDemographic); db.SaveChanges(); return(Ok(customerDemographic)); }
public void Insert(string CustomerTypeID,string CustomerDesc) { CustomerDemographic item = new CustomerDemographic(); item.CustomerTypeID = CustomerTypeID; item.CustomerDesc = CustomerDesc; item.Save(UserName); }
public void AddToCustomerDemographics(CustomerDemographic customerDemographic) { base.AddObject("CustomerDemographics", customerDemographic); }
public static CustomerDemographic CreateCustomerDemographic(string customerTypeID) { CustomerDemographic customerDemographic = new CustomerDemographic(); customerDemographic.CustomerTypeID = customerTypeID; return customerDemographic; }
partial void InsertCustomerDemographic(CustomerDemographic instance);
partial void UpdateCustomerDemographic(CustomerDemographic instance);
partial void DeleteCustomerDemographic(CustomerDemographic instance);
/// <summary> /// 保存实体信息 /// </summary> /// <param name="pEntity">实体对象</param> /// <returns>是否成功</returns> public void Save(CustomerDemographic pEntity) { HibernateDaoHelp.SaveOrUpdate(pEntity); }
public void Update(string CustomerTypeID,string CustomerDesc) { CustomerDemographic item = new CustomerDemographic(); item.MarkOld(); item.IsLoaded = true; item.CustomerTypeID = CustomerTypeID; item.CustomerDesc = CustomerDesc; item.Save(UserName); }