Пример #1
0
        private CardWithFile Mapper(SqlDataReader reader)
        {
            CardWithFile model = new CardWithFile();
            int          index = 0;

            model.Id          = reader.GetInt32(index++);
            model.Name        = reader.GetString(index++);
            model.Description = reader.GetString(index++);
            if (!reader.IsDBNull(index))
            {
                model.UserId = reader.GetInt32(index++);
            }
            else
            {
                index++;
            }
            model.AttackLevel    = reader.GetInt32(index++);
            model.DefenseLevel   = reader.GetInt32(index++);
            model.CardCombo      = reader.GetString(index++);
            model.CardComboAtk   = reader.GetInt32(index++);
            model.CardComboDef   = reader.GetInt32(index++);
            model.FileId         = reader.GetInt32(index++);
            model.UserFileName   = reader.GetString(index++);
            model.SystemFileName = reader.GetString(index++);
            model.FileUserId     = reader.GetInt32(index++);

            return(model);
        }
Пример #2
0
        public int Insert(CardWithFile model)
        {
            int id = 0;

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("Cards_Insert", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@FileId", model.FileId);
                    cmd.Parameters.AddWithValue("@Name", model.Name);
                    cmd.Parameters.AddWithValue("@Description", model.Description);
                    cmd.Parameters.AddWithValue("@AttackLevel", model.AttackLevel);
                    cmd.Parameters.AddWithValue("@DefenseLevel", model.DefenseLevel);
                    cmd.Parameters.AddWithValue("@UserId", model.UserId);
                    cmd.Parameters.AddWithValue("@CardCombo", model.CardCombo);
                    cmd.Parameters.AddWithValue("@CardComboAtk", model.CardComboAtk);
                    cmd.Parameters.AddWithValue("@CardComboDef", model.CardComboDef);

                    SqlParameter parm = new SqlParameter("@Id", SqlDbType.Int);
                    parm.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(parm);

                    cmd.ExecuteNonQuery();

                    id = (int)cmd.Parameters["@Id"].Value;
                }
                conn.Close();
            }
            return(id);
        }
Пример #3
0
        public HttpResponseMessage CardInsert(CardWithFile model)
        {
            try
            {
                ItemResponse <int> resp = new ItemResponse <int>();
                int id = svc.Insert(model);
                resp.Item = id;

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #4
0
 public HttpResponseMessage Put(int id, CardWithFile model)
 {
     try
     {
         //var user = _authService.GetCurrentUser();
         //model.ModifiedBy = user.Id;
         model.Id = id;
         svc.Update(model);
         SuccessResponse resp = new SuccessResponse();
         return(Request.CreateResponse(HttpStatusCode.OK, resp));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Пример #5
0
        public void Update(CardWithFile model)
        {
            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("Cards_Update", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", model.Id);
                    cmd.Parameters.AddWithValue("@AttackLevel", model.AttackLevel);
                    cmd.Parameters.AddWithValue("@DefenseLevel", model.DefenseLevel);
                    cmd.Parameters.AddWithValue("@CardCombo", model.CardCombo);
                    cmd.Parameters.AddWithValue("@CardComboAtk", model.CardComboAtk);
                    cmd.Parameters.AddWithValue("@CardComboDef", model.CardComboDef);

                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
        }
Пример #6
0
        public List <CardWithFile> SelectAll()
        {
            List <CardWithFile> cardList = new List <CardWithFile>();

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("Cards_SelectAll", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        CardWithFile model = Mapper(reader);
                        cardList.Add(model);
                    }
                }
                conn.Close();
            }
            return(cardList);
        }
Пример #7
0
        public CardWithFile SelectById(int id)
        {
            CardWithFile model = new CardWithFile();

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("Cards_SelectById", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", id);
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        model = Mapper(reader);
                    }
                }
                conn.Close();
            }
            return(model);
        }