public async Task <ActionResult> Delete(int id, [FromForm] Member model)
        {
            try
            {
                var client = new MemberClient(_config);

                var member = await client.Get(id);

                if (null == member)
                {
                    return(NotFound());
                }

                var response = await client.Delete(member);

                if (response.IsSuccessStatusCode)
                {
                    _toastNotification.AddSuccessToastMessage($"Le membre {member.Name} a été supprimée.");

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch
            {
                return(View(model));
            }

            return(View(model));
        }
Exemple #2
0
        public async Task <ActionResult> Edit(int meetingId, int attendeeId, [FromForm] AttendeeViewModel model)
        {
            var memberClient = new MemberClient(_config);
            var members      = await memberClient.GetAll();

            if (ModelState.IsValid)
            {
                try
                {
                    var client = new MeetingClient(_config);

                    var attendee = await client.GetAttendee(meetingId, attendeeId);

                    if (null == attendee)
                    {
                        return(NotFound());
                    }

                    if (null == model.MemberId)
                    {
                        attendee.Member = null;
                    }
                    else
                    {
                        attendee.Member = await memberClient.Get(model.MemberId.Value);

                        // Keep only the member alias
                        attendee.Member.Name = attendee.Member.Alias;
                    }

                    var response = await client.UpdateAttendee(meetingId, attendee);

                    if (response.IsSuccessStatusCode)
                    {
                        _toastNotification.AddSuccessToastMessage($"Le participant a été modifiée.");

                        return(RedirectToAction("Details", "Meetings", new { Id = meetingId }));
                    }
                }
                catch
                {
                    model.Members = members.Select(p => new SelectListItem {
                        Value = p.Id.ToString(), Text = p.Alias
                    }).ToList();

                    return(View(model));
                }
            }

            model.Members = members.Select(p => new SelectListItem {
                Value = p.Id.ToString(), Text = p.Alias
            }).ToList();

            return(View(model));
        }
        public async Task <ActionResult> Accept(int id, [FromForm] AcceptViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var meetingClient = new MeetingClient(_config);
                    var memberClient  = new MemberClient(_config);

                    var attendee = await meetingClient.GetAttendee(id, model.AttendeeId);

                    if (null == attendee)
                    {
                        return(BadRequest("Attendee not found"));
                    }

                    var member = await memberClient.Get(model.MemberId);

                    if (null == member)
                    {
                        return(BadRequest("Member not found"));
                    }

                    if (null == attendee.Member)
                    {
                        attendee.Member = new Member();
                    }

                    attendee.Member.Id   = member.Id;
                    attendee.Member.Name = member.Alias;

                    var response = await meetingClient.UpdateAttendee(id, attendee);

                    if (response.IsSuccessStatusCode)
                    {
                        _toastNotification.AddSuccessToastMessage($"Merci, le role {attendee.Role.Name} a été assigné à {attendee.Member.Name}.");

                        CookieOptions option = new CookieOptions();

                        option.Expires = DateTime.Now.AddYears(1);

                        Response.Cookies.Append("member", member.Id.ToString(), option);

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch
                {
                    return(View(model));
                }
            }

            return(View(model));
        }
        // GET: Members/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var client = new MemberClient(_config);

            var Member = await client.Get(id);

            if (null == Member)
            {
                return(NotFound());
            }

            return(View(Member));
        }
        public async Task <ActionResult> Edit(int id, [FromForm] Member model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var client = new MemberClient(_config);

                    var member = await client.Get(id);

                    if (null == member)
                    {
                        return(NotFound());
                    }

                    member.Active  = model.Active;
                    member.Alias   = model.Alias;
                    member.Email   = model.Email;
                    member.Notify  = model.Notify;
                    member.Email2  = model.Email2;
                    member.Notify2 = model.Notify2;
                    member.Email3  = model.Email3;
                    member.Notify3 = model.Notify3;
                    member.Name    = model.Name;
                    member.Note    = model.Note;

                    var response = await client.Update(member);

                    if (response.IsSuccessStatusCode)
                    {
                        _toastNotification.AddSuccessToastMessage($"Le membre {model.Name} a été modifiée.");

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch
                {
                    return(View());
                }
            }

            return(View(model));
        }