Example #1
0
        /// <summary>
        /// Изменение стенда
        /// </summary>
        /// <param name="_stands">Стенд</param>
        /// <returns></returns>
        public async Task <Stands> UpdateStendAsync(Stands _stands)
        {
            switch (Properties.Settings.Default.GetDataFrom)
            {
            case "db":
                using (var standsContext = new StandsContext())
                {
                    standsContext.Entry(_stands).State = EntityState.Modified;

                    await standsContext.SaveChangesAsync();
                }
                break;

            case "Json":
                GRADEXPO.Models.Stands stands = new GRADEXPO.Models.Stands()
                {
                    expoId      = _stands.expoId,
                    description = _stands.description,
                    hall        = _stands.hall,
                    vendorId    = _stands.vendorId
                };
                string json = JsonConvert.SerializeObject(stands, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Ignore
                });
                string res = await HttpClient.Browser.ByMethodAsync(string.Format("{0}{1}({2})", Properties.Settings.Default.BaseUrlApi, Properties.Settings.Default.postfixGetStand, _stands.standId), json, "PUT");

                break;
            }
            return(_stands);
        }
Example #2
0
        /// <summary>
        /// Добавления нового стенда
        /// </summary>
        /// <param name="_stand">Стенд</param>
        /// <returns></returns>
        public async Task <Stands> AddStandAsync(Stands _stand)
        {
            Stands result = null;

            switch (Properties.Settings.Default.GetDataFrom)
            {
            case "db":
                using (var standsContext = new StandsContext())
                {
                    result = standsContext.Stands.Add(_stand);
                    await standsContext.SaveChangesAsync();
                }
                break;

            case "Json":
                string json = JsonConvert.SerializeObject(_stand, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Ignore
                });
                string res = await HttpClient.Browser.ByMethodAsync(string.Format("{0}{1}", Properties.Settings.Default.BaseUrlApi, Properties.Settings.Default.postfixGetStand), json, "POST");

                result = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <Stands>(res, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }));

                break;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Удаление стенда
        /// </summary>
        /// <param name="_standId">id стенда</param>
        /// <returns></returns>
        public async Task DeleteStendsAsync(int _standId)
        {
            switch (Properties.Settings.Default.GetDataFrom)
            {
            case "db":
                using (var standsContext = new StandsContext())
                {
                    var stand = await standsContext.Stands.FirstOrDefaultAsync(f => f.standId == _standId);

                    standsContext.Entry(stand).State = EntityState.Deleted;

                    await standsContext.SaveChangesAsync();
                }
                break;

            case "Json":
                break;
            }
        }