public async Task <ActionResult> Create(Participant participant)
        {
            try
            {
                /// Сбор данных Встреча-Участник
                Dictionary <string, object> participantInMeetDict = new Dictionary <string, object>();
                participantInMeetDict.Add("participant", participant);
                participantInMeetDict.Add("meet", new Meet()
                {
                    Id = participant.CurrentMeet
                });

                /// Конвертация в Json-тело запроса
                string        jsonParticipantInMeet = JsonConvert.SerializeObject(participantInMeetDict);
                StringContent bodyPostData          = new StringContent(jsonParticipantInMeet, Encoding.UTF8, WebApiHelper.BaseMediaType);
                string        resultRequest         = await WebApiHelper.ExecuteWebApiRequest <string>($"api/Meets/AddParticipantInMeet", WebApiHelper.HttpMethod.POST, bodyPostData);

                ViewData["message"] = resultRequest;
                return(await Create());
            }
            catch (Exception ex)
            {
                ViewData["message"] = ex.Message;

                return(await Create());
            }
        }
Exemple #2
0
        /// <summary>
        /// Инициализация объектов БД в сервисе
        /// </summary>
        private static void InitParams()
        {
            DbEntities = WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(SettingsApp.Default.DefaultServiceHost,
                                                                                  "api/ParamsEntities",
                                                                                  WebApiHelper.HttpMethod.GET)?.Result;
            int missedEntitiesCount;

            if (DbEntities == null)
            {
                missedEntitiesCount = SettingsApp.Default.MaxEntities;
            }
            else
            {
                missedEntitiesCount = SettingsApp.Default.MaxEntities - DbEntities.Count;
            }

            if (missedEntitiesCount > 0)
            {
                for (int i = 0; i < missedEntitiesCount; i++)
                {
                    UpdateRandomEntity(EntityService.GetNewRandomEntity(), true);
                }

                DbEntities = WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(SettingsApp.Default.DefaultServiceHost,
                                                                                      "api/ParamsEntities",
                                                                                      WebApiHelper.HttpMethod.GET)?.Result;
            }
        }
Exemple #3
0
        /// <summary>
        /// Обновить объект сущности
        /// </summary>
        /// <param name="entity">Объект сущности</param>
        /// <param name="isCreate">Создать объект в БД</param>
        private static bool UpdateRandomEntity(ParamsEntity entity, bool isCreate)
        {
            try
            {
                WebApiHelper.HttpMethod _method;
                string uri;

                if (!isCreate)
                {
                    _method = WebApiHelper.HttpMethod.PUT;
                    uri     = $"api/ParamsEntities/{entity.Id}";
                }
                else
                {
                    _method = WebApiHelper.HttpMethod.POST;
                    uri     = $"api/ParamsEntities";
                }

                /// Конвертация в Json-тело запроса
                string        jsonMeet     = JsonConvert.SerializeObject(entity);
                StringContent bodyPostData = new StringContent(jsonMeet, Encoding.UTF8, WebApiHelper.BaseMediaType);
                Task <string> task         = WebApiHelper.ExecuteWebApiRequest <string>(SettingsApp.Default.DefaultServiceHost, uri, _method, bodyPostData);
                task.Wait();

                return(task.IsCompleted && !task.IsFaulted);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
 public void TestGetTableEntities()
 {
     System.Threading.Tasks.Task <List <ParamsEntity> > data = WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(UrlBase, "api/ParamsEntities", WebApiHelper.HttpMethod.GET);
     data.Wait();
     Assert.IsNotNull(data.Result);
     Assert.AreEqual(data.IsFaulted, false);
 }
        public async Task <ActionResult> Create()
        {
            List <Meet> resultRequest = await WebApiHelper.ExecuteWebApiRequest <List <Meet> >("api/Meets", WebApiHelper.HttpMethod.GET);

            SelectList meets = new SelectList(resultRequest, "Id", "Title");

            ViewBag.Meets = meets;

            return(View());
        }
        public async Task <ActionResult> Edit(Participant participant)
        {
            string        participantJson = JsonConvert.SerializeObject(participant);
            StringContent bodyPostData    = new StringContent(participantJson, Encoding.UTF8, WebApiHelper.BaseMediaType);
            Participant   resultRequest   = await WebApiHelper.ExecuteWebApiRequest <Participant>($"api/Participants", WebApiHelper.HttpMethod.POST, bodyPostData);

            ViewData["message"] = "Participant update completed successfully!";

            return(View(resultRequest));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                await WebApiHelper.ExecuteWebApiRequest <Meet>($"api/Meets/{id}", WebApiHelper.HttpMethod.DELETE);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <ActionResult> Edit(Meet meet)
        {
            try
            {
                string        meetJson      = JsonConvert.SerializeObject(meet);
                StringContent bodyPostData  = new StringContent(meetJson, Encoding.UTF8, WebApiHelper.BaseMediaType);
                string        resultRequest = await WebApiHelper.ExecuteWebApiRequest <string>($"api/Meets", WebApiHelper.HttpMethod.POST, bodyPostData);

                ViewData["message"] = resultRequest;

                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public async Task <ActionResult> Create(Meet meet)
        {
            try
            {
                /// Конвертация в Json-тело запроса
                string        jsonMeet      = JsonConvert.SerializeObject(meet);
                StringContent bodyPostData  = new StringContent(jsonMeet, Encoding.UTF8, WebApiHelper.BaseMediaType);
                string        resultRequest = await WebApiHelper.ExecuteWebApiRequest <string>($"api/Meets", WebApiHelper.HttpMethod.POST, bodyPostData);

                ViewData["message"] = resultRequest;
                return(Create());
            }
            catch (Exception ex)
            {
                ViewData["message"] = ex.Message;
                return(Create());
            }
        }
 /// <summary>
 /// Получение контента данных представления
 /// </summary>
 /// <returns>Контент таблицы сущностей</returns>
 public async Task <ActionResult> Index()
 {
     return(View(await WebApiHelper.ExecuteWebApiRequest <List <ParamsEntity> >(ConfigurationManager.AppSettings["ServiceHost"],
                                                                                "api/ParamsEntities",
                                                                                WebApiHelper.HttpMethod.GET)));
 }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            await WebApiHelper.ExecuteWebApiRequest <Participant>($"api/Participants/{id}", WebApiHelper.HttpMethod.DELETE);

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Delete(int?id)
        {
            Participant resultRequest = await WebApiHelper.ExecuteWebApiRequest <Participant>($"api/Participants/{id}", WebApiHelper.HttpMethod.GET);

            return(View(resultRequest));
        }
 public async Task <ActionResult> Index()
 {
     return(View(await WebApiHelper.ExecuteWebApiRequest <List <Participant> >("api/Participants", WebApiHelper.HttpMethod.GET)));
 }
        public async Task <ActionResult> Delete(int id)
        {
            Meet resultRequest = await WebApiHelper.ExecuteWebApiRequest <Meet>($"api/Meets/{id}", WebApiHelper.HttpMethod.GET);

            return(View(resultRequest));
        }
Exemple #15
0
 /// <summary>
 /// Сформировать отчет участников встречи
 /// </summary>
 /// <returns></returns>
 public async Task <ActionResult> Index()
 {
     return(View(await WebApiHelper.ExecuteWebApiRequest <List <MeetParticipantGroup> >($"api/Meets/MeetsWithParticipantsList", WebApiHelper.HttpMethod.GET)));
 }