public void DeleteSupplierTermTest() { // Get a test user var user = GetTestUser(); var testCompany = GetTestCompany(user); // Create a record SupplierTermModel model = createSupplierTerm(testCompany); var error = LookupService.InsertOrUpdateSupplierTerm(model, user, ""); Assert.IsTrue(!error.IsError, error.Message); // Check that it was written var result = db.FindSupplierTerm(model.Id); var test = LookupService.MapToModel(result); AreEqual(model, test); // Now delete it LookupService.DeleteSupplierTerm(model.Id); // And check that is was deleted result = db.FindSupplierTerm(model.Id); Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed"); }
public Error InsertOrUpdateSupplierTerm(SupplierTermModel term, UserModel user, string lockGuid) { var error = validateModel(term); if (!error.IsError) { // Check that the lock is still current if (!db.IsLockStillValid(typeof(SupplierTerm).ToString(), term.Id, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "SupplierTermName"); } else { SupplierTerm temp = null; if (term.Id != 0) { temp = db.FindSupplierTerm(term.Id); } if (temp == null) { temp = new SupplierTerm(); } Mapper.Map <SupplierTermModel, SupplierTerm>(term, temp); db.InsertOrUpdateSupplierTerm(temp); term.Id = temp.Id; } } return(error); }
private SupplierTermModel createSupplierTerm(CompanyModel company) { var model = new SupplierTermModel { CompanyId = company.Id, SupplierTermName = RandomString(), Enabled = true }; return(model); }
public SupplierTermModel FindSupplierTermModel(int id, bool bCreateEmptyIfNotfound = true) { SupplierTermModel model = null; var term = db.FindSupplierTerm(id); if (term == null) { if (bCreateEmptyIfNotfound) { model = new SupplierTermModel(); } } else { model = MapToModel(term); } return(model); }
private Error validateModel(SupplierTermModel model) { var error = isValidRequiredInt(model.CompanyId, "CompanyId", EvolutionResources.errModelFieldValueRequired); if (!error.IsError) { error = isValidRequiredString(getFieldValue(model.SupplierTermName), 50, "SupplierTermName", EvolutionResources.errTextDataRequiredInField); } if (!error.IsError) { // Check if a record with the same name already exists var term = db.FindSupplierTerm(model.CompanyId, model.SupplierTermName); if (term != null && // Record was found ((term.Id == 0 || // when creating new or term.Id != model.Id))) // when updating existing { error.SetError(EvolutionResources.errItemAlreadyExists, "SupplierTermName"); } } return(error); }
public string LockSupplierTerm(SupplierTermModel model) { return(db.LockRecord(typeof(SupplierTerm).ToString(), model.Id)); }
public SupplierTermModel Clone(SupplierTermModel term) { var model = Mapper.Map <SupplierTermModel, SupplierTermModel>(term); return(model); }