Example #1
0
        public ActionResult DisplayQuotationLinkageDialog(int? orderID)
        {
            bool isSuccess = true;
            StringBuilder htmlString = new StringBuilder();

            try
            {
                string linkageString = string.Empty;
                IEnumerable<int> quotationIDs = (from r in this._db.recsys_relate
                                                 where r.table1 == "quotation" && r.table2 == "order" && r.id2 == orderID
                                                 select r.id1).ToList();
                if (quotationIDs != null && quotationIDs.Count() > 0)
                {
                    foreach (int quotationID in quotationIDs)
                    {
                        linkageString = linkageString + ", " + quotationID.ToString();
                    }
                    linkageString = linkageString.Trim(',');
                }
                else
                {
                    linkageString = "沒有任何連結";
                }

                ECallQuotationLinkageModel model = new ECallQuotationLinkageModel()
                {
                    orderID = orderID.Value,
                    existingLinkageString = linkageString
                };
                htmlString.Append(this.RenderPartialViewToString(string.Format(_ViewPath, "QuotationLinkageDialog"), model));
            }
            catch
            {
                isSuccess = false;
            }
            return Json(
                new
                {
                    isSuccess = isSuccess,
                    htmlString = htmlString.ToString()
                });
        }
Example #2
0
        public ActionResult QuotationLinkageSave(ECallQuotationLinkageModel model)
        {
            bool isSuccess = true;
            string errorType = string.Empty;
            try
            {
                if (model.quotationID.HasValue)
                {
                    bool isQuotationExist = (this._db.recsys_quotation.Where(q => q.id == model.quotationID).Count() > 0);
                    if (!isQuotationExist)
                    {
                        isSuccess = false;
                        errorType = "Not-Exist-Quotation";
                    }
                    else
                    {
                        bool isExist = (from r in this._db.recsys_relate
                                        where r.table1 == "quotation" && r.table2 == "order" && r.id1 == model.quotationID && r.id2 == model.orderID
                                        select r).Count() > 0;

                        if (isExist)
                        {
                            isSuccess = false;
                            errorType = "Linkage-Exist";
                        }
                        else
                        {
                            int quotationRawCustomerID = (from q in this._db.recsys_quotation
                                                          join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id
                                                          where q.id == model.quotationID
                                                          select rc.customer_id).FirstOrDefault();
                            int orderRawCustomerID = (from o in this._db.recsys_order
                                                      join rc in this._db.recsys_relate_customers on o.customer_id equals rc.id
                                                      where o.id == model.orderID
                                                      select rc.customer_id).FirstOrDefault();

                            if (quotationRawCustomerID != orderRawCustomerID)
                            {
                                isSuccess = false;
                                errorType = "Customer-Not-Match";
                            }
                            else
                            {
                                recsys_relate newRelation = new recsys_relate
                                {
                                    table1 = "quotation",
                                    table2 = "order",
                                    id1 = model.quotationID.Value,
                                    id2 = model.orderID
                                };
                                this._db.recsys_relate.AddObject(newRelation);
                                this._db.SaveChanges();
                            }
                        }
                    }
                }
                else
                {
                    isSuccess = false;
                    errorType = "Wrong-Quotation-ID";
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return Json(new { isSuccess = isSuccess, errorType = errorType });
        }