示例#1
0
        public int AddGiftType(GiftTypeBE mod)
        {
            EntityDE ety = new EntityDE();
            ety.SiteCode = mod.SiteCode;
            ety.EntityTypeCode = mod.EntityTypeCode;
            ety.EntityName = mod.EntityName;
            ety.Code = mod.Code;

            int retVal = 0;
            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);
            try
            {
                _bdmSvc = new BDMService();
                StringBuilder sb = new StringBuilder();
                using (TransactionScope trans = new TransactionScope())
                {
                    mod.ID = _bdmSvc.AddEntity(ety);

                    SqlCommand cmd = new SqlCommand();

                    #region CommandText & Params

                    sb.Append("INSERT INTO [dbo].[GiftType]");
                    sb.Append("([GiftTypeID]");
                    sb.Append(",[IsCondition]");
                    sb.Append(",[Price])");
                    sb.Append("VALUES");
                    sb.Append("(@GiftTypeID");
                    sb.Append(",@IsCondition");
                    sb.Append(",@Price)");

                    cmd.Parameters.AddWithValue("@GiftTypeID", mod.ID);
                    cmd.Parameters.AddWithValue("@IsCondition", mod.IsCondition);
                    cmd.Parameters.AddWithValue("@Price", mod.Price);

                    #endregion

                    cmd.Connection = con;

                    cmd.CommandText = sb.ToString();
                    con.Open();

                    cmd.ExecuteNonQuery();
                    retVal = mod.ID;
                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                retVal = -1;
            }
            finally
            {
                con.Close();
            }

            return retVal;
        }
示例#2
0
        public void CRUD_GiftType()
        {
            var list = _alKhairSvc.GetViewOfAllGiftTypes("QST", EntityTypeCodes.GFT.ToString());
            GiftTypeBE mod = new GiftTypeBE();
            mod.IsCondition = true;
            mod.Price = 400;
            mod.SiteCode = "QST";
            mod.EntityTypeCode = "GFT";
            mod.EntityName = "Khairaat";
            mod.Code = "020";

            _alKhairSvc = new AlKhairService();
            int id = _alKhairSvc.AddGiftType(mod);

            //ety.ID = id;
            //ety.EntityName = "Khariraat ...";
            //bool res = _bdmSvc.ModifyEntity(ety);
        }
示例#3
0
 public GiftTypeViewModel()
 {
     GiftType = new GiftTypeBE();
     GiftTypes = new List<GiftTypeView>();
 }
        public GiftTypeViewModel ModifyGiftType(GiftTypeBE mod)
        {
            GiftTypeViewModel model = new GiftTypeViewModel();

            try
            {
                DBOperations op = mod.IsActive ? DBOperations.Update : DBOperations.Delete;
                mod.SiteCode = AppConstants.SITE_CODE;
                model.GiftType = mod;
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    //_bdmSvc.ModifyEntity(mod);
                    _alKhairSvc.ModifyGiftType(mod);

                    model.FieldId = "code";
                    model.GiftType = new GiftTypeBE();
                    model.GiftTypes = _alKhairSvc.GetViewOfAllGiftTypes(AppConstants.SITE_CODE, EntityTypeCodes.GFT.ToString());
                    model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, "Gift Type") : string.Format(AppConstants.CRUD_DELETE, "Gift Type");
                }
            }
            catch (Exception ex)
            {
                model.IsValid = false;
                model.Message = ex.Message;
                if (ex.Message.Contains("Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."))
                    model.Message = "Unable to modify Region Code";
            }
            return model;
        }
示例#5
0
        public bool ModifyGiftType(GiftTypeBE mod)
        {
            EntityDE ety = new EntityDE();
            ety.SiteCode = mod.SiteCode;
            ety.EntityTypeCode = mod.EntityTypeCode;
            ety.ID = mod.ID;
            ety.EntityName = mod.EntityName;
            ety.Code = mod.Code;
            ety.IsActive = mod.IsActive;

            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);
            try
            {
                //mod.ID = GetNextEntityId(mod.SiteCode, mod.EntityTypeCode);
                StringBuilder sb = new StringBuilder();
                using (TransactionScope trans = new TransactionScope())
                {
                    _bdmSvc = new BDMService();
                    if (_bdmSvc.ModifyEntity(ety))
                    {
                        SqlCommand cmd = new SqlCommand();

                        #region CommandText & Params

                        sb.Append("UPDATE [dbo].[GiftType] SET ");
                        sb.Append("[GiftTypeID] = @GiftTypeID");
                        sb.Append(",[IsCondition] = @IsCondition");
                        sb.Append(",[Price] = @Price");
                        sb.Append(" WHERE ");
                        sb.Append(" [GiftTypeID] = @GiftTypeID");

                        cmd.Parameters.AddWithValue("@GiftTypeID", mod.ID);
                        cmd.Parameters.AddWithValue("@IsCondition", mod.IsCondition);
                        cmd.Parameters.AddWithValue("@Price", mod.Price);

                        #endregion

                        cmd.Connection = con;
                        cmd.CommandText = sb.ToString();
                        con.Open();

                        cmd.ExecuteNonQuery();
                        trans.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                con.Close();
            }

            return true;
        }