예제 #1
0
        private ActionResult Add(EnqueryGridRecordBase data, int? masterCustomerID, int Status2)
        {
            bool isSuccess = false;

            Member member = new Member("users");
            recsys_customers masterCustomer = null;
            recsys_relate_customers newCustomerData;
            recsys_enquery newRecord;

            try
            {
                if (masterCustomerID.HasValue)
                    masterCustomer = this._db.recsys_customers.FirstOrDefault(theCustomer => theCustomer.id == masterCustomerID);

                newCustomerData = new recsys_relate_customers()
                {
                    customer_id = masterCustomerID.HasValue ? masterCustomerID.Value : -1,
                    name = masterCustomer == null ? null : masterCustomer.name,
                    manual_input_code = masterCustomer == null ? null : masterCustomer.manual_input_code,
                    code = masterCustomer == null ? null : masterCustomer.code,
                    prefix = masterCustomer == null ? null : masterCustomer.prefix,
                    contact = data.Contact,
                    customer_code = masterCustomer == null ? null : masterCustomer.customer_code,
                    type = masterCustomer == null ? (byte?) null : masterCustomer.type,
                    tel2 = data.Tel,
                    email = data.EMail,
                    relate_type = (int)CustomerDataRelateType.Enquery
                };

                this._db.recsys_relate_customers.AddObject(newCustomerData);
                this._db.SaveChanges();
                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newCustomerData);

                if (newCustomerData.id <= 0)
                    return Json(false, JsonRequestBehavior.AllowGet);

                newRecord = new recsys_enquery()
                {
                    create_date = DateTime.Now,
                    customer_id = newCustomerData.id,
                    last_update = DateTime.Now,
                    remark = data.Remark,
                    sBookingInformation = data.BookingInformation,
                    status = (byte) Status2,
                    update_user_id = (int)member.infoBySession("id")
                };

                this._db.recsys_enquery.AddObject(newRecord);

                this._db.SaveChanges();

                isSuccess = true;
            }
            catch (OptimisticConcurrencyException)
            {
                //# log down
            }

            return Json(isSuccess, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        public ActionResult Edit(EnqueryGridRecordBase data, int? masterCustomerID, int Status2)
        {
            bool isSuccess = false;

            Member member = new Member("users");
            recsys_enquery oldRecord;
            recsys_relate_customers oldRecordCustomerData;

            oldRecord = this._db.recsys_enquery.FirstOrDefault(theRecord => theRecord.id == data.ID);

            if (oldRecord == null)
                return Json(false, JsonRequestBehavior.AllowGet);

            oldRecordCustomerData = this._db.recsys_relate_customers.FirstOrDefault(theCustomerData => theCustomerData.id == oldRecord.customer_id);

            if (oldRecordCustomerData == null)
                return Json(false, JsonRequestBehavior.AllowGet);

            oldRecord.sBookingInformation = data.BookingInformation;
            oldRecord.remark = data.Remark;
            oldRecord.last_update = DateTime.Now;
            oldRecord.status = (byte) Status2;
            oldRecord.update_user_id = (int)member.infoBySession("id");

            oldRecordCustomerData.contact = data.Contact;
            oldRecordCustomerData.tel2 = data.Tel;
            oldRecordCustomerData.email = data.EMail;

            if (masterCustomerID.HasValue)
            {
                recsys_customers masterCustomer = this._db.recsys_customers.FirstOrDefault(theCustomer => theCustomer.id == masterCustomerID.Value);
                if (masterCustomer != null)
                {
                    oldRecordCustomerData.customer_id = masterCustomerID.Value;
                    oldRecordCustomerData.name = masterCustomer.name;
                    oldRecordCustomerData.manual_input_code = masterCustomer.manual_input_code;
                    oldRecordCustomerData.code = masterCustomer.code;
                    oldRecordCustomerData.prefix = masterCustomer.prefix;
                    oldRecordCustomerData.customer_code = masterCustomer.customer_code;
                    oldRecordCustomerData.type = masterCustomer.type;
                }
            }

            try
            {
                this._db.SaveChanges();
                isSuccess = true;
            }
            catch (OptimisticConcurrencyException)
            {
                //# log down
            }

            return Json(isSuccess, JsonRequestBehavior.AllowGet);
        }