public void ToRender([ARDataBind("purchase",AutoLoadBehavior.Always)] Purchase purchase, string comment) { PurchaseStatusChange psc = new PurchaseStatusChange(); psc.Created = DateTime.Now; psc.Purchase = purchase; psc.StatusOld = purchase.Status; psc.StatusNew =Purchase.StatusPurchase.Entregado; psc.author = Context.CurrentUser.Identity.Name.ToLower (); purchase.DateDelivery = System.DateTime.Now; purchase.Status = Purchase.StatusPurchase.Entregado; using (TransactionScope t1 = new TransactionScope()) { try { purchase.Save (); psc.Save (); 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 (); } t1.VoteCommit(); Flash["TypeMsg"] = "alert alert-success"; Flash["Msg"] = "<b>Ok, Solicitud " + purchase.Status +" entregada conforme...</b> "; } catch (Exception ex) { t1.VoteRollBack(); if (!purchase.IsValid()) { Flash["Msg"] = Utilities.GetValidationErrorText(purchase.ValidationErrorMessages); } else { Flash["Msg"] = "Error :" + ex.Message + " " + comment.Length.ToString(); } RedirectToReferrer (); return; } } PropertyBag["to"] = ConfigurationManager.AppSettings["mailadmin"]; PropertyBag["cc"] = purchase.UserRequest + "@" + ConfigurationManager.AppSettings["defaultdomain"]; PropertyBag["from"] = ConfigurationManager.AppSettings["mailadmin"]; PropertyBag["subject"] = "[compras] Compra recepcionada "+ purchase.Status +" ID:" + purchase.Id.ToString (); PropertyBag["purchase"] = purchase; PropertyBag["purchaseproducts"] = purchase.PurchaseProducts; DeliverEmail(RenderMailMessage ("close",null,PropertyBag)); RenderView ("approval"); }
public void ToApprove([ARDataBind("purchase",AutoLoadBehavior.Always)] Purchase purchase, string response, string comment) { PurchaseStatusChange psc = new PurchaseStatusChange(); psc.Created = DateTime.Now; psc.Purchase = purchase; psc.StatusOld = purchase.Status; switch (response) { case "approval" : { purchase.Status = Purchase.StatusPurchase.Aprobada; break; } case "reject" : { purchase.Status = Purchase.StatusPurchase.Rechazada; break; } default : { Flash["TypeMsg"] = "alert alert-error"; Flash["Msg"] = "Error :" + response; RedirectToReferrer (); return; } } psc.StatusNew = purchase.Status; psc.author = Context.CurrentUser.Identity.Name.ToLower (); purchase.DateApproval = System.DateTime.Now; using (TransactionScope t1 = new TransactionScope()) { try { purchase.Save (); psc.Save (); 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 (); } t1.VoteCommit(); Flash["TypeMsg"] = "alert alert-success"; Flash["Msg"] = "<b>Ok, Solicitud " + purchase.Status +" enviada a Compras</b> "; } catch (Exception ex) { t1.VoteRollBack(); Flash["TypeMsg"] = "alert alert-error"; Flash["Msg"] = "Error :" + ex.Message; RedirectToReferrer (); return; } } PropertyBag["to"] = ConfigurationManager.AppSettings["mailadmin"]; PropertyBag["cc"] = purchase.UserRequest + "@" + ConfigurationManager.AppSettings["defaultdomain"]; PropertyBag["from"] = ConfigurationManager.AppSettings["mailadmin"]; PropertyBag["subject"] = "[compras] Compra "+ purchase.Status +" ID:" + purchase.Id.ToString (); PropertyBag["purchase"] = purchase; PropertyBag["purchaseproducts"] = purchase.PurchaseProducts; DeliverEmail(RenderMailMessage ("toapprove",null,PropertyBag)); if (purchase.Status == Purchase.StatusPurchase.Aprobada) RenderView ("approval"); else RenderView ("reject"); }