/// <summary> /// Insert /// </summary> /// <param name="CommentId"></param> /// <returns></returns> public Message Insert(PurchaseComment objUI) { Message msg = null; try { if (objUI != null) { // Set more info dbContext.PurchaseComments.InsertOnSubmit(objUI); dbContext.SubmitChanges(); // Show success message msg = new Message(MessageConstants.I0001, MessageType.Info, objUI.Poster,"added a comment"); } } catch { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }
/// <summary> /// Insert /// </summary> /// <param name="CommentId"></param> /// <returns></returns> public Message Insert(PurchaseComment objUI) { Message msg = null; try { if (objUI != null) { // Set more info dbContext.PurchaseComments.InsertOnSubmit(objUI); dbContext.SubmitChanges(); // Show success message msg = new Message(MessageConstants.I0001, MessageType.Info, "Purchase Request \"" + Constants.PR_REQUEST_PREFIX + objUI.RequestID + "\"", "added a comment"); } } catch { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }
/// <summary> /// Update approval with comment /// </summary> /// <param name="objUI">PurchaseRequest</param> /// <param name="objComment">PurchaseComment</param> /// <returns>Message</returns> public Message UpdateForApproval(PurchaseRequest objUI, PurchaseComment objComment) { Message msg = null; DbTransaction trans = null; try { dbContext.Connection.Open(); trans = dbContext.Connection.BeginTransaction(); dbContext.Transaction = trans; if (objUI != null) { PurchaseRequest objDb = GetByID(objUI.ID); if (objDb != null) { #region Insert Comment if (objComment != null && !string.IsNullOrEmpty(objComment.Contents)) { PurchaseRequestCommentDao commentDao = new PurchaseRequestCommentDao(); commentDao.Insert(objComment); } #endregion // Check valid update date if (IsValidUpdateDate(objUI, objDb, out msg)) { objDb.WFResolutionID = objUI.WFResolutionID; objDb.AssignID = objUI.AssignID; objDb.AssignRole = objUI.AssignRole; objDb.InvolveID = objUI.InvolveID; objDb.InvolveRole = objUI.InvolveRole; objDb.InvolveDate = objUI.InvolveDate; objDb.UpdateDate = DateTime.Now; dbContext.SubmitChanges(); msg = new Message(MessageConstants.I0001, MessageType.Info, " Purchase Request '" + Constants.PR_REQUEST_PREFIX + objUI.ID + "'", "updated"); trans.Commit(); } else { trans.Rollback(); } } } } catch { // Rollback transaction if (trans != null) { trans.Rollback(); } // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } finally { if ((trans.Connection != null) && (trans.Connection.State == System.Data.ConnectionState.Open)) { trans.Connection.Close(); } } return msg; }
/// <summary> /// Update purchase comment /// </summary> /// <param name="objUI">PurchaseComment</param> private void UpdatePurchaseComment(PurchaseComment objUI) { PurchaseComment objCommentDb = GetCommentByID(objUI.ID); if (objCommentDb != null) { if (!string.IsNullOrEmpty(objUI.Contents)) { objCommentDb.Contents = objUI.Contents; dbContext.SubmitChanges(); } else { dbContext.PurchaseComments.DeleteOnSubmit(objUI); dbContext.SubmitChanges(); } } }
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"); }
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); } else { Flash["Msg"] = "Error :" + ex.Message; } RedirectToAction("new"); return; } } PropertyBag["to"] = ca.Login + "@" + ca.Domain; PropertyBag["from"] = ConfigurationManager.AppSettings["mailadmin"]; PropertyBag["subject"] = "[compras] Solicitud Aprobacion ID:" + purchase.Id.ToString (); PropertyBag["idpurchase"] = purchase.Id; PropertyBag["username"] = purchase.NameUserRequest; PropertyBag["datepurchase"] = purchase.DateRequest.ToString (); DeliverEmail(RenderMailMessage ("approver",null,PropertyBag)); }