本文整理汇总了C#中Purchase.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# Purchase.IsValid方法的具体用法?C# Purchase.IsValid怎么用?C# Purchase.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Purchase
的用法示例。
在下文中一共展示了Purchase.IsValid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: submit
public void submit([ARDataBind("purchaseproducts")] PurchaseProduct[] purchaseproducts, int companyid, int userapproval, int familyproductid, string comment, HttpPostedFile uploadedFile)
{
Purchase purchase = new Purchase();
purchase.UserRequest = Context.CurrentUser.Identity.Name.ToLower ();
purchase.DateRequest = System.DateTime.Now;
User user = (User) Context.Session["user"];
purchase.MailRequest = user.Mail;
purchase.NameUserRequest = user.Cn;
if (companyid > 0)
purchase.Company = Company.FindById(companyid);
else {
Flash["TypeMsg"] = "alert alert-error";
Flash["Msg"] = "Seleccionar Compañia";
RedirectToAction("new");
return;
}
CompanyApprover ca = new CompanyApprover();
if (userapproval > 0) {
ca = CompanyApprover.FindById(userapproval);
purchase.UserApproval = ca;
} else {
Flash["TypeMsg"] = "alert alert-error";
Flash["Msg"] = "Seleccionar Aprobador";
RedirectToAction("new");
return;
}
if (familyproductid < 1) {
Flash["TypeMsg"] = "alert alert-error";
Flash["Msg"] = "Seleccionar Familia de Productos";
RedirectToAction("new");
return;
}
purchase.Status = Purchase.StatusPurchase.En_Aprobacion;
using (TransactionScope t1 = new TransactionScope())
{
try {
//purchase.BudgetValue = Budget.FindByCompanyFamilyProduct(Company.FindById(companyid), FamilyProduct.FindById(familyproductid)).Value;
purchase.familyproduct = FamilyProduct.FindById(familyproductid);
purchase.Save ();
int cont = 0;
foreach(PurchaseProduct pp in purchaseproducts)
{
if (pp.Checked) {
pp.Purchase = purchase;
//pp.Product = Product.FindById(1);
if (!pp.IsValid()) {
Flash["TypeMsg"] = "alert alert-error";
Flash["Msg"] = Utilities.GetValidationErrorText(pp.ValidationErrorMessages);
t1.VoteRollBack ();
RedirectToAction("new");
return;
}
pp.Save();
cont++;
}
}
if (cont == 0) {
t1.VoteRollBack ();
Flash["TypeMsg"] = "alert alert-error";
Flash["Msg"] = "Seleccionar Productos";
RedirectToAction("new");
return;
}
if (!string.IsNullOrEmpty(comment)) {
PurchaseComment pc = new PurchaseComment();
pc.Comment = comment;
pc.Created = DateTime.Now;
pc.Purchase = purchase;
pc.UserComment = Context.CurrentUser.Identity.Name.ToLower ();
pc.Save ();
}
if (uploadedFile != null) {
PurchaseAttachment pa = new PurchaseAttachment();
pa.Purchase = purchase;
pa.Name = uploadedFile.FileName;
pa.Created = DateTime.Now;
pa.Path = Guid.NewGuid().ToString("N") + uploadedFile.FileName;
pa.Save ();
uploadedFile.SaveAs("../upload_compras/"+pa.Path);
}
t1.VoteCommit ();
Flash["TypeMsg"] = "alert alert-success";
Flash["Msg"] = "Solicitud generada con ID :<b>" + purchase.Id.ToString() + "</b>";
}
catch (Exception ex) {
t1.VoteRollBack ();
Flash["TypeMsg"] = "alert alert-error";
if (!purchase.IsValid()) {
Flash["Msg"] = Utilities.GetValidationErrorText(purchase.ValidationErrorMessages);
//.........这里部分代码省略.........