• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Validation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Validation的典型用法代码示例。如果您正苦于以下问题:C# Validation类的具体用法?C# Validation怎么用?C# Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Validation类属于命名空间,在下文中一共展示了Validation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:32,代码来源:BidderCheckoutService.cs


示例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;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:30,代码来源:BidderDeletionService.cs


示例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();
            }
        }
开发者ID:whesius,项目名称:allors,代码行数:29,代码来源:Initialization.cs


示例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;
 }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:26,代码来源:DonorEventAssociationService.cs


示例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;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:29,代码来源:EventService.cs


示例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;
            }
        }
开发者ID:m12k,项目名称:Files,代码行数:34,代码来源:FormModule.cs


示例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;
        }
开发者ID:gitter-badger,项目名称:aaLog,代码行数:43,代码来源:aaLogReaderModularInput.cs


示例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;
 }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:26,代码来源:ItemService.cs


示例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;
 }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:26,代码来源:DonorEventAssociationService.cs


示例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);
 }
开发者ID:runeapetersen,项目名称:ArgumentValidator,代码行数:7,代码来源:TfValidation.cs


示例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;
 }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:27,代码来源:UserService.cs


示例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;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:25,代码来源:UserService.cs


示例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);
 }
开发者ID:jagui,项目名称:bricks-toolkit,代码行数:7,代码来源:ValidationTest.cs


示例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;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:26,代码来源:CategoryDeletionService.cs


示例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");
            }
        }
开发者ID:dinet,项目名称:PMS,代码行数:26,代码来源:AddExporter.xaml.cs


示例16: CreateBidder

        public Validation CreateBidder(ref Bidder eventBidder,
                                       long currentUserId)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("CreateBidder");

            try
            {
                val = _validator.ValidateNewBidder(eventBidder, ref trans);
                if(val.IsValid)
                {
                    eventBidder.Number = _repo.GetByEvent(eventBidder.EventId, ref trans).Select(b => b.Number).Max() + 1;
                    eventBidder.CreatedBy = currentUserId;
                    _repo.Insert(ref eventBidder, ref trans);
                }
                trans.Commit();
            }
            catch(Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to create bidder: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:30,代码来源:BidderService.cs


示例17: DeleteDonor

        public Validation DeleteDonor(long donorId)
        {
            IAuctionTransaction trans = _factory.BuildTransaction("DeleteDonor");

            var val = new Validation();
            try
            {
                if (!_validator.CanDonorBeDeleted(donorId, ref trans))
                {
                    val.AddError("Donor cannot be deleted");
                }
                else
                {
                    _repo.RemoveFromAllEvents(donorId, ref trans);
                    _repo.Delete(donorId, ref trans);
                }
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to delete Donor: {0}", ex.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
开发者ID:danappleyard,项目名称:auction-csharp,代码行数:30,代码来源:DonorDeletionService.cs


示例18: ShouldAddAddErrorFromNormalErrorToListItemError

 public void ShouldAddAddErrorFromNormalErrorToListItemError()
 {
     Validation validation = new Validation();
     validation.AddError("test", "Hello");
     Validation listValidation = new Validation();
     listValidation.AddErrorFrom(1, validation);
     Assert.AreEqual(1, listValidation.Errors.Count);
 }
开发者ID:jagui,项目名称:bricks-toolkit,代码行数:8,代码来源:ValidationTest.cs


示例19: RetrieveListErrorFromValidationWhichContainsNonListErrors

 public void RetrieveListErrorFromValidationWhichContainsNonListErrors()
 {
     Validation validation = new Validation();
     validation.AddError("a", "m");
     validation.AddError("a", "m", 0);
     validation.AddError("a", "m", 1);
     Assert.AreEqual(1, validation.ErrorOn(0).Count);
 }
开发者ID:jagui,项目名称:bricks-toolkit,代码行数:8,代码来源:ValidationTest.cs


示例20: ObjectIsRequiredShouldBeValid

 public void ObjectIsRequiredShouldBeValid()
 {
     var data = new TestData {ANullableInt = 10};
     var validator = new Validation<TestData>(data);
     var result = validator.IsRequired(p => p.ANullableInt).ReadResults();
     Assert.IsTrue(result.IsValid);
     Assert.AreEqual(0, result.ValidationResults.Count);
 }
开发者ID:cezar-gradinariu,项目名称:Gems,代码行数:8,代码来源:ValidationTests.cs



注:本文中的Validation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ValidationContext类代码示例发布时间:2022-05-24
下一篇:
C# ValidatableArgument类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap