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;
        }
Beispiel #2
0
        //[TestMethod]
        public void AddEntity()
        {
            _bdmSvc = new BDMService();
            EntityDE ety = new EntityDE();
            ety.EntityName = "Imran Farooq";
            ety.EntityTypeCode = EntityTypes.MGR.ToString();
            ety.SiteCode = AppConstants.SITE_CODE;

            AddressDE add = new AddressDE(AddressTypes.Personal.ToString());
            add.AddressLine1 = "St. Ahmad Din Sipahi";
            add.AddressLine2 = "Moh. Fatu Pura, Gujrat";

            ContactDE contact = new ContactDE();
            contact.Mobile1 = "0333-348343499";

            ety.Addresses.Add(add);
            ety.Contacts.Add(contact);

            decimal retVal = _bdmSvc.AddEntity(ety);
        }
Beispiel #3
0
        public bool ModifyEntity(EntityDE mod)
        {
            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);
            try
            {
                //mod.ID = GetNextEntityId(mod.SiteCode, mod.EntityTypeCode);
                StringBuilder sb = new StringBuilder();
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required))
                {
                    SqlCommand cmd = new SqlCommand();

                    #region CommandText & Params

                    sb.Append("UPDATE [dbo].[Entity] SET ");
                    sb.Append("[Code] = @Code");
                    sb.Append(",[EntityName] = @EntityName");
                    sb.Append(",[IsActive] = @IsActive");
                    sb.Append(" WHERE ");
                    sb.Append(" [SiteCode] = @SiteCode");
                    sb.Append(" AND [ID] = @ID");
                    sb.Append(" AND [EntityTypeCode] = @EntityTypeCode");

                    cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                    cmd.Parameters.AddWithValue("@ID", mod.ID);
                    cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                    cmd.Parameters.AddWithValue("@Code", mod.Code);
                    cmd.Parameters.AddWithValue("@EntityName", mod.EntityName);
                    cmd.Parameters.AddWithValue("@IsActive", mod.IsActive);

                    #endregion

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

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

            return true;
            //_etyRepo.Update(mod);
            //foreach (var add in mod.Addresses)
            //    _addRepo.Update(add);
            //foreach (var cnt in mod.Contacts)
            //    _cntRepo.Update(cnt);
            ////_uow.Context.Entry(mod).State =  EntityState.Modified;
            //_etyRepo.CommitAllChanges();
        }
Beispiel #4
0
        public EntityDE GetEntityById(string siteCode, string entityTypeCode, int id)
        {
            EntityDE mod = new EntityDE();
            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);

            try
            {
                //using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required))
                {
                    StringBuilder sb = new StringBuilder();
                    SqlCommand cmd = new SqlCommand();
                    sb.Append("SELECT * FROM  [dbo].[Entity]");
                    sb.Append(" WHERE [SiteCode] = @SiteCode");
                    sb.Append(" AND [EntityTypeCode]=@EntityTypeCode");
                    sb.Append(" AND [ID]=@ID");

                    cmd.Parameters.AddWithValue("@SiteCode", siteCode);
                    cmd.Parameters.AddWithValue("@EntityTypeCode", entityTypeCode);
                    cmd.Parameters.AddWithValue("@ID", id);

                    cmd.Connection = con;
                    cmd.CommandText = sb.ToString();
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            mod.Code = rdr["Code"] != DBNull.Value ? (string)rdr["Code"] : string.Empty;
                            mod.EntityName = rdr["EntityName"] != DBNull.Value ? (string)rdr["EntityName"] : string.Empty;
                            mod.IsActive = rdr["IsActive"] != DBNull.Value ? (bool)rdr["IsActive"] : false;
                        }
                    }
                    else
                        mod = null;

                    //trans.Complete();
                }
            }
            catch (Exception ex)
            {
                mod = null;
            }
            finally
            {
                con.Close();
            }
            return mod;
        }
Beispiel #5
0
        //private int AddEntity(EntityDE mod, )
        public int AddEntity(EntityDE mod)
        {
            int retVal = 0;
            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);

            try
            {

                //trans.Commit();
                mod.ID = GetNextEntityId(mod.SiteCode, mod.EntityTypeCode);
                StringBuilder sb = new StringBuilder();
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required))
                {
                    SqlCommand cmd = new SqlCommand();

                    #region CommandText & Params

                    sb.Append("INSERT INTO [dbo].[Entity]");
                    sb.Append("([SiteCode]");
                    sb.Append(",[ID]");
                    sb.Append(",[EntityTypeCode]");
                    sb.Append(",[Code]");
                    sb.Append(",[EntityName]");
                    sb.Append(",[IsActive])");
                    sb.Append("VALUES");
                    sb.Append("(@SiteCode");
                    sb.Append(",@ID");
                    sb.Append(",@EntityTypeCode");
                    sb.Append(",@Code");
                    sb.Append(",@EntityName");
                    sb.Append(",@IsActive)");

                    cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                    cmd.Parameters.AddWithValue("@ID", mod.ID);
                    cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                    cmd.Parameters.AddWithValue("@Code", mod.Code);
                    cmd.Parameters.AddWithValue("@EntityName", mod.EntityName);
                    cmd.Parameters.AddWithValue("@IsActive", mod.IsActive);

                    #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;
        }
Beispiel #6
0
        public void Entity_CRUD()
        {
            EntityDE ety = new EntityDE();
            ety.SiteCode = "QST";
            ety.EntityTypeCode = "DNR";
            ety.EntityName = "Khairaat";
            ety.Code = "090";

            _bdmSvc = new BDMService();
            int id = _bdmSvc.AddEntity(ety);

            ety.ID = id;
            ety.EntityName = "Khariraat ...";
            bool res = _bdmSvc.ModifyEntity(ety);

            res = _bdmSvc.DeleteEntity(ety.SiteCode, ety.EntityTypeCode, ety.ID);
        }
Beispiel #7
0
 public ManagerViewModel()
 {
     Address = new AddressDE();
     Contact = new ContactDE();
     Manager = new EntityDE(EntityTypes.MGR);
     Managers = new List<EntityView>();
     Cities = new List<CityDE>();
     Areas = new List<AreaDE>();
     Regions = new List<RegionDE>();
 }
        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;
        }