本文整理汇总了C#中Validation类的典型用法代码示例。如果您正苦于以下问题:C# Validation类的具体用法?C# Validation怎么用?C# Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Validation类属于命名空间,在下文中一共展示了Validation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckoutBidder
public Validation CheckoutBidder(long eventId, int number, long userId)
{
var val = new Validation();
IAuctionTransaction trans = _factory.BuildTransaction("CheckoutBidder");
try
{
var bidder = _bidderRepo.GetByNumberAndEvent(number, eventId, ref trans);
var packages = _packageRepo.GetByBidder(bidder.Id, ref trans).Where(p => !p.Paid);
if(packages.Count() == 0)
{
throw new ApplicationException("No packages to checkout");
}
packages.ToList().ForEach(p => { p.Paid = true; _packageRepo.Update(ref p, ref trans); });
bidder.CheckedoutBy = userId;
_bidderRepo.Update(ref bidder, ref trans);
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
val.AddError(string.Format("Unable to checkout bidder: {0}", ex.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例2: DeleteBidder
public Validation DeleteBidder(long eventId, int number)
{
//we need to check that they do not have any closedout/checkedout packages
//we can delete only if they do not
var val = new Validation();
var trans = _factory.BuildTransaction("DeleteBidder");
try
{
var bidder = _repo.GetByNumberAndEvent(number, eventId, ref trans);
if (_packageRepo.GetByBidder(bidder.Id, ref trans).Count > 0)
{
throw new ApplicationException("Bidder is associated with packages");
}
_repo.Delete(bidder.Id, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to delete bidder: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例3: Execute
internal void Execute()
{
this.validation = new Validation(this.database);
this.AllowSnapshotIsolation();
if (this.validation.IsValid)
{
this.TruncateTables();
}
else
{
this.CreateSchema();
this.DropProcedures();
this.DropTables();
this.CreateTables();
this.DropTableTypes();
this.CreateTableTypes();
this.CreateProcedures();
this.CreateIndeces();
}
}
示例4: RemoveDonorFromEvent
public Validation RemoveDonorFromEvent(long donorId,
long eventId)
{
var val = new Validation();
//verify that they are not already in event
var trans = _factory.BuildTransaction("RemoveDonorFromEvent");
try
{
if (_itemRepo.GetByDonorAndEvent(donorId, eventId, ref trans).Count > 0)
{
throw new ApplicationException("Event items are associated with the donor");
}
_repo.RemoveFromEvent(donorId, eventId, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to add donor to event: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例5: CreateEvent
public Validation CreateEvent(ref Event auctionEvent,
long currentUserId)
{
var val = new Validation();
var trans = _factory.BuildTransaction("CreateEvent");
try
{
val = _validator.ValidateNewEvent(auctionEvent, ref trans);
if (val.IsValid)
{
auctionEvent.CreatedBy = currentUserId;
_repo.Insert(ref auctionEvent, ref trans);
}
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to create auction: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例6: Initialize
private void Initialize()
{
try
{
classModule = new ClassModule(Global.ProjectConnectionString, Global.ProjectDataProvider);
Validation = new Validation();
Validation.Validate(this);
if (Operation == Global.Operation.UPDATE || Operation == Global.Operation.VIEW)
{
DataRow dr;
dr = classModule.GetProjectModuleDetails(ModuleId);
textBoxID.Text = ModuleId;
textBoxModuleName.Text = dr["mod_name"].ToString();
textBoxModuleName.Tag = dr["mod_name"].ToString();
textBoxDescription.Text = dr["mod_desc"].ToString();
if (Operation == Global.Operation.VIEW)
{
userControlButtonsSave.Visible = false;
Lock();
}
}
textBoxModuleName.Focus();
}
catch (Exception)
{
throw;
}
}
示例7: Validate
/// <summary>
/// Check that the values of arguments specified for a newly created or edited instance of
/// this modular input are valid. If they are valid, set <tt>errorMessage</tt> to <tt>""</tt>
/// and return <tt>true</tt>. Otherwise, set <tt>errorMessage</tt> to an informative explanation
/// of what makes the arguments invalid and return <tt>false</tt>.
/// </summary>
/// <param name="validation">a Validation object specifying the new argument values.</param>
/// <param name="errorMessage">an output parameter to pass back an error message.</param>
/// <returns><tt>true</tt> if the arguments are valid and <tt>false</tt> otherwise.</returns>
public override bool Validate(Validation validation, out string errorMessage)
{
bool returnValue = true;
errorMessage = "";
try
{
string logfilepath = ((SingleValueParameter)(validation.Parameters["logfilepath"])).ToString();
Int32 cycletimeint = ((SingleValueParameter)(validation.Parameters["cycletime"])).ToInt32();
// Verify path is valid
if (returnValue && !System.IO.Directory.Exists(logfilepath))
{
errorMessage = "LogFilePath " + logfilepath + " does not exist on local machine";
return false;
}
//Verify cycle time is minimum value (250 ms)
if (returnValue && (cycletimeint < 250))
{
errorMessage = "cycle time must be at least 250ms";
return false;
}
}
catch(Exception)
{
errorMessage = "Error processing validation logic.";
returnValue = false;
}
return returnValue;
}
示例8: DeleteItem
public Validation DeleteItem(long itemId)
{
//we do not want to delete an item if it is in a package
var trans = _factory.BuildTransaction("DeleteItem");
var val = new Validation();
try
{
var item = _repo.Get(itemId, ref trans);
if (item.PackageId.HasValue)
{
throw new ApplicationException("Item is in a package");
}
_repo.Delete(itemId, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to delete item: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例9: AddDonorToEvent
public Validation AddDonorToEvent(long donorId,
long eventId)
{
var val = new Validation();
//verify that they are not already in event
var trans = _factory.BuildTransaction("AddDonorToEvent");
try
{
if (_eventRepo.GetEventListByDonor(donorId, ref trans).Contains(eventId))
{
throw new ApplicationException("Donor is already associated with the event");
}
_repo.AddToEvent(donorId, eventId, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to add donor to event: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例10: InternalExceptions_AddMultipleExceptions_ShouldPass
public void InternalExceptions_AddMultipleExceptions_ShouldPass()
{
Validation val = new Validation();
val.AddException(new Exception());
val.AddException(new Exception());
Assert.True(val.Exceptions.Count() == 2);
}
示例11: DeleteUser
public Validation DeleteUser(long userId)
{
//why would we not want to delete a user?
//we cannot delete a user if they are the account admin
var trans = _factory.BuildTransaction("DeleteUser");
var val = new Validation();
try
{
var user = _repo.Get(userId, ref trans);
if (_accountRepo.GetMainUserId(user.AccountId, ref trans) == userId)
{
throw new ApplicationException("User is account admin");
}
_repo.DeleteUser(userId, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to create user: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例12: InsertUser
public Validation InsertUser(ref User user)
{
var val = new Validation();
var trans = _factory.BuildTransaction("InsertUser");
try
{
//validate
if (val.IsValid)
{
_repo.Insert(ref user, ref trans);
}
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to create user: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例13: ShouldNotAllowMultipleLogicalErrorsForMessageAndObjectPair
public void ShouldNotAllowMultipleLogicalErrorsForMessageAndObjectPair()
{
Validation validation = new Validation();
validation.AddError("test", "Hello", DateTime.Today.Date);
validation.AddError("test", "Hello", DateTime.Today.Date);
Assert.AreEqual(1, validation.ErrorOn(DateTime.Today.Date).Count);
}
示例14: DeleteCategory
public Validation DeleteCategory(long categoryId)
{
var val = new Validation();
IAuctionTransaction trans = _factory.BuildTransaction("DeleteCategory");
try
{
if (_packageRepo.GetByCategory(categoryId, ref trans).Count > 0)
{
throw new ApplicationException("Category is associated with packages");
}
_repo.Delete(categoryId, ref trans);
trans.Commit();
}
catch (Exception e)
{
trans.Rollback();
val.AddError(string.Format("Unable to delete category: {0}", e.Message));
}
finally
{
trans.Dispose();
}
return val;
}
示例15: button_Save_Click
private void button_Save_Click(object sender, RoutedEventArgs e)
{
Validation validation = new Validation();
//validation for emails
if (validation.ValidateTextField(txtEmail.Text) ? validation.ValidateEmail(txtEmail.Text) : true)
{
exporter.Name = txtName.Text;
exporter.RegNo = txtRegNo.Text;
exporter.TelNo = txtTelNo.Text;
exporter.ShortTag = txtShortTag.Text;
exporter.Email = txtEmail.Text;
exporter.Description = txtDescription.Text;
exporter.Address = txtAddress.Text;
//adding to data model
model.AddToExporters(exporter);
//applying changes to the database
model.SaveChanges();
ContentPresenter con = (ContentPresenter)this.VisualParent;
con.Content = new AddDirector(exporter);
}
else
{
MessageBox.Show("Invalid Email");
}
}