Beispiel #1
0
        public async Task <ThanksCard> PostThanksCardAsync(ThanksCard thanksCard)
        {
            var jObject = JsonConvert.SerializeObject(thanksCard);

            //Make Json object into content type
            var content = new StringContent(jObject);

            //Adding header of the contenttype
            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            ThanksCard responseThanksCard = null;

            try
            {
                var response = await Client.PostAsync(this.BaseUrl + "/api/ThanksCard", content);

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    responseThanksCard = JsonConvert.DeserializeObject <ThanksCard>(responseContent);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception in RestService.PostThanksCardAsync: " + e);
            }
            return(responseThanksCard);
        }
        async void ExecuteThanksCardDeleteCommand(ThanksCard SelectedThanksCard)
        {
            ThanksCard deletedThanksCard = await SelectedThanksCard.DeleteThanksCardAsync(SelectedThanksCard.Id);

            // ユーザ一覧 ThanksCards を更新する。
            this.UpdateThanksCards();
        }
Beispiel #3
0
        public async Task <IActionResult> PutThanksCard(long id, ThanksCard thanksCard)
        {
            if (id != thanksCard.Id)
            {
                return(BadRequest());
            }

            _context.Entry(thanksCard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ThanksCardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #4
0
        public async Task <ActionResult <ThanksCard> > PostThanksCard(ThanksCard thanksCard)
        {
            _context.ThanksCards.Add(thanksCard);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetThanksCard", new { id = thanksCard.Id }, thanksCard));
        }
Beispiel #5
0
        async void ExecuteSubmitCommand()
        {
            System.Diagnostics.Debug.WriteLine(this.Tags);

            //選択された Tag を取得し、ThanksCard.ThanksCardTags にセットする。
            List <ThanksCardTag> ThanksCardTags = new List <ThanksCardTag>();

            foreach (var tag in this.Tags.Where(t => t.Selected))
            {
                ThanksCardTag thanksCardTag = new ThanksCardTag();
                thanksCardTag.TagId = tag.Id;
                ThanksCardTags.Add(thanksCardTag);
            }
            this.ThanksCard.ThanksCardTags = ThanksCardTags;

            ThanksCard createdThanksCard = await ThanksCard.PostThanksCardAsync(this.ThanksCard);

            //TODO: Error handling
            this.regionManager.RequestNavigate("ContentRegion", nameof(Views.ThanksCardList));

            const string message =
                "送信しました";
            const string caption = "お知らせ";

            System.Windows.Forms.MessageBox.Show(message, caption,
                                                 MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #6
0
        public async void Submit()
        {
            ThanksCard createdThanksCard = await ThanksCard.PostThanksCardAsync(this.ThanksCard);

            //TODO: Error handling
            Messenger.Raise(new WindowActionMessage(WindowAction.Close, "Created"));
        }
Beispiel #7
0
        public async Task <IActionResult> PutThanksCard(long id, ThanksCard thanksCard)
        {
            if (id != thanksCard.Id)
            {
                return(BadRequest());
            }

            // Department には既に存在しているユーザが入るため、更新の対象から外す。
            //_context.Departments.Attach(user.Department);

            _context.Entry(thanksCard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ThanksCardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
            ThanksCard thanksCard = new ThanksCard();

            this.ThanksCards = await thanksCard.GetThanksCardsAsync();

            this.UpdateThanksCards();
        }
        public async Task <ActionResult <ThanksCard> > Post([FromBody] ThanksCard thanksCard)
        {
            _context.ThanksCards.Add(thanksCard);
            await _context.SaveChangesAsync();

            // TODO: Error Handling
            return(thanksCard);
        }
        void ExecuteThanksCardReplyCommand(ThanksCard SelectedThanksCard)
        {
            // 対象のUserをパラメーターとして画面遷移先に渡す。
            var parameters = new NavigationParameters();

            parameters.Add("SelectedThanksCard", SelectedThanksCard);

            this.regionManager.RequestNavigate("ContentRegion", nameof(Views.ThanksCardReply), parameters);
        }
Beispiel #11
0
        async void ExecuteSubmitCommand()
        {
            System.Diagnostics.Debug.WriteLine(this.Categorys);

            ThanksCard createdThanksCard = await ThanksCard.PostThanksCardAsync(this.ThanksCard);

            //TODO: Error handling
            this.regionManager.RequestNavigate("ContentRegion", nameof(Views.ThanksCardList));
        }
Beispiel #12
0
        public async Task <ActionResult <ThanksCard> > Post([FromBody] ThanksCard thanksCard)
        {
            // From, To には既に存在しているユーザが入るため、更新の対象から外す。
            //_context.Users.Attach(thanksCard.From);
            //_context.Users.Attach(thanksCard.To);

            _context.ThanksCards.Add(thanksCard);
            await _context.SaveChangesAsync();

            // TODO: Error Handling
            return(thanksCard);
        }
        async void ExecuteSubmitCommand()
        {
            System.Diagnostics.Debug.WriteLine(this.Tags);
            //選択された Tag を取得し、ThanksCard.ThanksCardTags にセットする。
            List <ThanksCardTag> ThanksCardTags = new List <ThanksCardTag>();

            foreach (var tag in this.Tags.Where(t => t.Selected))
            {
                ThanksCardTag thanksCardTag = new ThanksCardTag();
                thanksCardTag.TagId = tag.Id;
                ThanksCardTags.Add(thanksCardTag);
            }
            this.ThanksCard.ThanksCardTags = ThanksCardTags;
            ThanksCard createdThanksCard = await ThanksCard.PostThanksCardAsync(this.ThanksCard);

            //TODO: Error handling
            this.regionManager.RequestNavigate("ContentRegion", nameof(Views.ThanksCardList));
        }
        public async Task <ThanksCard> DeleteThanksCardAsync(long Id)
        {
            ThanksCard responseThanksCard = null;

            try
            {
                var response = await Client.DeleteAsync(this.BaseUrl + "/api/ThanksCard/" + Id);

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    responseThanksCard = JsonConvert.DeserializeObject <ThanksCard>(responseContent);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception in RestService.DeleteThanksCardAsync: " + e);
            }
            return(responseThanksCard);
        }
        public async void Initialize()
        {
            ThanksCard thanksCard = new ThanksCard();

            this.ThanksCards = await thanksCard.GetThanksCardsAsync();
        }
        async void ExecuteSubmitCommand()
        {
            ThanksCard updatedThanskCard = await ThanksCard.PutThanksCardAsync(this.ThanksCard);

            this.regionManager.RequestNavigate("ContentRegion", nameof(Views.ThanksCardList));
        }
        private async void UpdateThanksCards()
        {
            var thanksCard = new ThanksCard();

            this.ThanksCards = await thanksCard.GetThanksCardsAsync();
        }
Beispiel #18
0
        public LINQTest(AppDbContext context)
        {
            this._context = context;

            // Usersテーブルが空なら初期データを作成する。
            if (_context.Users.Count() == 0)
            {
                var dept1 = new Department {
                    Code = 1, Name = "dept1", Parent = null
                };
                var dept2 = new Department {
                    Code = 2, Name = "dept2", Parent = dept1
                };
                _context.Departments.Add(dept1);
                _context.Departments.Add(dept2);

                var admin = new User {
                    Name = "admin", Password = "******", IsAdmin = true, Department = dept1
                };
                var user1 = new User {
                    Name = "user1", Password = "******", IsAdmin = false, Department = dept1
                };
                var user2 = new User {
                    Name = "user2", Password = "******", IsAdmin = false, Department = dept2
                };
                _context.Users.Add(admin);
                _context.Users.Add(user1);
                _context.Users.Add(user2);

                var tag1 = new Tag {
                    Name = "tag1"
                };
                var tag2 = new Tag {
                    Name = "tag2"
                };
                var tag3 = new Tag {
                    Name = "tag3"
                };
                _context.Tags.Add(tag1);
                _context.Tags.Add(tag2);
                _context.Tags.Add(tag3);

                var thanksCard1 = new ThanksCard {
                    Title = "title1", Body = "body1", From = admin, To = user1, CreatedDateTime = DateTime.Now
                };
                var thanksCard2 = new ThanksCard {
                    Title = "title2", Body = "body2", From = admin, To = user1, CreatedDateTime = DateTime.Now
                };
                var thanksCard3 = new ThanksCard {
                    Title = "title3", Body = "body3", From = admin, To = user1, CreatedDateTime = DateTime.Now
                };
                var thanksCard4 = new ThanksCard {
                    Title = "title4", Body = "body4", From = admin, To = user2, CreatedDateTime = DateTime.Now
                };
                var thanksCard5 = new ThanksCard {
                    Title = "title5", Body = "body5", From = admin, To = user2, CreatedDateTime = DateTime.Now
                };
                var thanksCard6 = new ThanksCard {
                    Title = "title6", Body = "body6", From = user1, To = admin, CreatedDateTime = DateTime.Now
                };
                var thanksCard7 = new ThanksCard {
                    Title = "title7", Body = "body7", From = user2, To = admin, CreatedDateTime = DateTime.Now
                };

                _context.ThanksCards.Add(thanksCard1);
                _context.ThanksCards.Add(thanksCard2);
                _context.ThanksCards.Add(thanksCard3);
                _context.ThanksCards.Add(thanksCard4);
                _context.ThanksCards.Add(thanksCard5);
                _context.ThanksCards.Add(thanksCard6);
                _context.ThanksCards.Add(thanksCard7);

                var thanksCardTag1 = new ThanksCardTag {
                    ThanksCard = thanksCard1, Tag = tag1
                };
                var thanksCardTag2 = new ThanksCardTag {
                    ThanksCard = thanksCard1, Tag = tag2
                };
                var thanksCardTag3 = new ThanksCardTag {
                    ThanksCard = thanksCard2, Tag = tag2
                };
                var thanksCardTag4 = new ThanksCardTag {
                    ThanksCard = thanksCard2, Tag = tag3
                };
                _context.ThanksCardTags.Add(thanksCardTag1);
                _context.ThanksCardTags.Add(thanksCardTag2);
                _context.ThanksCardTags.Add(thanksCardTag3);
                _context.ThanksCardTags.Add(thanksCardTag4);

                _context.SaveChanges();
            }

            // Data テーブルが空なら初期データを作成する。
            if (_context.Data.Count() == 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    Data data = new Data {
                        Value = i * 10 + (i * i), DateTime = DateTime.Now
                    };
                    _context.Data.Add(data);
                }
                _context.SaveChanges();
            }
        }