Ejemplo n.º 1
0
        public bool InsertCategoryType(b2bCategoryType CategoryType)
        {
            var svCategory = new CategoryService();
            var Cate       = svCategory.SelectData <b2bCategoryType>(" * ", "IsDelete = 0 AND RowFlag > 0 AND CategoryTypeName = '" + CategoryType.CategoryTypeName + "'");

            if (Cate.Count() != 1)
            {
                CategoryType.CreatedDate  = DateTimeNow;
                CategoryType.ModifiedDate = DateTimeNow;
                CategoryType.CreatedBy    = "sa";
                CategoryType.ModifiedBy   = "sa";

                using (var trans = new TransactionScope())
                {
                    qDB.b2bCategoryTypes.InsertOnSubmit(CategoryType);
                    qDB.SubmitChanges();
                    trans.Complete();
                    IsResult = true;
                }
            }
            else
            {
                IsResult = false;
            }
            return(IsResult);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool InsertProductShipment(b2bProductShipment model)
 {
     // default
     model.RowFlag      = 1;
     model.RowVersion   = 1;
     model.CreatedBy    = "sa";
     model.CreatedDate  = DateTimeNow;
     model.ModifiedBy   = "sa";
     model.ModifiedDate = DateTimeNow;
     qDB.b2bProductShipments.InsertOnSubmit(model);// ทำการ save
     qDB.SubmitChanges();
     IsResult = true;
     return(IsResult);
 }
Ejemplo n.º 3
0
        public T SaveData <T>(T Model, string PrimaryKeyName) where T : class
        {
            #region Members
            IsResult = true;
            Type serviceType = this.GetType();
            #endregion

            #region Validation
            MethodInfo validateMethod = serviceType.GetMethod(Model.GetType().Name + "Validate");
            if (validateMethod != null)
            {
                if (false == (bool)validateMethod.Invoke(this, new object[] { Model }))
                {
                    return(Model);
                }
            }
            #endregion

            #region DoSave
            using (var trans = new TransactionScope())
            {
                try
                {
                    var table = qDB.GetTable <T>();

                    int result = 0;
                    Int32.TryParse(Model.GetType().GetProperty(PrimaryKeyName).GetValue(Model, null).ToString(), out result);
                    if (result > 0)
                    {
                        qDB.Refresh(RefreshMode.KeepCurrentValues, Model);
                    }
                    else
                    {
                        table.InsertOnSubmit(Model);
                    }

                    qDB.SubmitChanges();
                    trans.Complete();
                }
                catch (Exception ex)
                {
                    IsResult = false;
                    MsgError.Add(ex);
                }
            }
            #endregion

            return(Model);
        }