public ActionResult CloneQuotationPackages(int? id) { //# validation if (!id.HasValue) return Json(new { bIsSuccessful = false }); bool isSuccessful = true; Member member = new Member("users"); int newQuotationPackageID = 0; string newCode = ""; string message = "複製失敗!請重試"; try { //# get existing quotation package recsys_quotation_packages existingQuotationPackage = this._db.recsys_quotation_packages.FirstOrDefault(theQuotationPackage => theQuotationPackage.id == id.Value); if (existingQuotationPackage != null) { //# get existing quotation package items IEnumerable<recsys_quotation_package_items> existingQuotationPackageItems = (from qpi in this._db.recsys_quotation_package_items where qpi.quotation_package_id == id && qpi.status == 1 orderby qpi.nSequence select qpi).ToList(); //# check repeated quotation package code newCode = existingQuotationPackage.code + " (Copy)"; var quotationPackages = from qp in this._db.recsys_quotation_packages where qp.status == 1 select qp; foreach (recsys_quotation_packages quotationPackage in quotationPackages) { if (newCode.Trim().ToUpper() == quotationPackage.code.Trim().ToUpper()) { message = "已有Quotation Package (" + newCode + ")"; return Json( new { bIsSuccessful = false, message = message }); } } //# construct new quotation package recsys_quotation_packages newQuotationPackage = new recsys_quotation_packages(); newQuotationPackage.package_name = existingQuotationPackage.package_name; newQuotationPackage.code = newCode; newQuotationPackage.remark = existingQuotationPackage.remark; newQuotationPackage.price = existingQuotationPackage.price; newQuotationPackage.status = 1; newQuotationPackage.create_date = DateTime.Now; newQuotationPackage.update_date = DateTime.Now; newQuotationPackage.create_by = (int)member.infoBySession("id"); newQuotationPackage.update_by = (int)member.infoBySession("id"); newQuotationPackage.district_id = existingQuotationPackage.district_id; newQuotationPackage.customer_type = existingQuotationPackage.customer_type; this._db.recsys_quotation_packages.AddObject(newQuotationPackage); //# save quotation package this._db.SaveChanges(); //# load new quotation package this._db.Refresh(RefreshMode.StoreWins, newQuotationPackage); newQuotationPackageID = newQuotationPackage.id; //# construct new quotation package items recsys_quotation_package_items[] newQuotationPackageItems = existingQuotationPackageItems.Select(theItem => QuotationPackagesController.CopyQuotationPackageItem(theItem)).ToArray(); foreach (recsys_quotation_package_items item in newQuotationPackageItems) { item.quotation_package_id = newQuotationPackageID; this._db.recsys_quotation_package_items.AddObject(item); } //# save data this._db.SaveChanges(); //# load new items this._db.Refresh(RefreshMode.StoreWins, newQuotationPackageItems); } //# clone quotation package //# save changes } catch (OptimisticConcurrencyException) { //# log down } return Json(new { bIsSuccessful = isSuccessful, newCode = newCode, newQuotationPackageID = newQuotationPackageID, message = message }); }
/// <summary> /// Create a new recsys_quotation_packages object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="package_name">Initial value of the package_name property.</param> /// <param name="code">Initial value of the code property.</param> /// <param name="status">Initial value of the status property.</param> /// <param name="create_date">Initial value of the create_date property.</param> /// <param name="create_by">Initial value of the create_by property.</param> public static recsys_quotation_packages Createrecsys_quotation_packages(global::System.Int32 id, global::System.String package_name, global::System.String code, global::System.Byte status, global::System.DateTime create_date, global::System.Int32 create_by) { recsys_quotation_packages recsys_quotation_packages = new recsys_quotation_packages(); recsys_quotation_packages.id = id; recsys_quotation_packages.package_name = package_name; recsys_quotation_packages.code = code; recsys_quotation_packages.status = status; recsys_quotation_packages.create_date = create_date; recsys_quotation_packages.create_by = create_by; return recsys_quotation_packages; }
public ActionResult DetailsAdd(recsys_quotation_packages data) { bool isSuccess = false; int id = 0; Member member = new Member("users"); data.status = 1; data.create_date = DateTime.Now; data.create_by = (int)member.infoBySession("id"); data.update_date = DateTime.Now; data.update_by = (int)member.infoBySession("id"); data.code = data.code.Trim(); if (data.package_name == null) data.package_name = ""; else data.package_name = data.package_name.Trim(); if (data.remark != null) data.remark = data.remark.Trim(); if (data.price == null) data.price = 0.0; var quotationPackages = from qp in this._db.recsys_quotation_packages where qp.status == 1 select qp; foreach (recsys_quotation_packages quotationPackage in quotationPackages) { if (!string.IsNullOrEmpty(data.code) && data.code.Trim().ToUpper() == quotationPackage.code.Trim().ToUpper()) { string message = "已有Quotation Package (" + data.code.Trim().ToUpper() + ")"; return Json( new { isSuccess = isSuccess, message = message }, JsonRequestBehavior.AllowGet); } } this._db.recsys_quotation_packages.AddObject(data); try { this._db.SaveChanges(); id = data.id; isSuccess = true; } catch (OptimisticConcurrencyException) { //# log down } // return Content(Common.json_encode(true)); return Json( new { isSuccess = isSuccess, newid = id }, JsonRequestBehavior.AllowGet); }
/// <summary> /// Deprecated Method for adding a new object to the recsys_quotation_packages EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTorecsys_quotation_packages(recsys_quotation_packages recsys_quotation_packages) { base.AddObject("recsys_quotation_packages", recsys_quotation_packages); }