public async Task <PartialViewResult> AddPerson(Guid guid)
        {
            IEnumerable <SelectListItem> types = from ActivityLogParticipantTypes t
                                                 in Enum.GetValues(typeof(ActivityLogParticipantTypes))
                                                 select new SelectListItem()
            {
                Value = ((int)t).ToString(),
                Text  = t.ToString()
            };

            ViewBag.TypesSelect = new SelectList(types, "Value", "Text");

            IEnumerable <ActivityLogPersonModel> availablePeople = await ActivityService.FindAllPeople();

            IEnumerable <ActivityLogParticipantModel> participantsInSession = ActivityService.ParticipantsInSession(Session,
                                                                                                                    guid);

            // Remove people from the available list who've already been added
            // in this session.
            if (participantsInSession != null && participantsInSession.Any())
            {
                availablePeople = availablePeople.Where(x => !participantsInSession.Any(y => y.Person.Id == x.Id));
            }

            ViewBag.PeopleSelect = new SelectList(availablePeople, "Id", "FullName");

            ActivityLogPersonCreateViewModel model = new ActivityLogPersonCreateViewModel()
            {
                SessionId = guid
            };

            return(PartialView(model));
        }
Пример #2
0
        public async Task <int> CreatePerson(ActivityLogPersonCreateViewModel createModel)
        {
            ActivityLogPersonModel model = new ActivityLogPersonModel()
            {
                FullName    = createModel.FullName,
                Email       = Formatter.SanitizeEmail(createModel.Email),
                Description = createModel.Description,
                PhoneNumber = createModel.PhoneNumber,
                SessionId   = createModel.SessionId
            };

            return(await ActivityLogPersonRepository.CreatePerson(model));
        }
        public async Task <JsonResult> AddPerson(ActivityLogPersonCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int id = await ActivityService.CreatePerson(model);

                    ActivityLogParticipantModel participant = new ActivityLogParticipantModel()
                    {
                        Person = new ActivityLogPersonModel()
                        {
                            Id          = id,
                            FullName    = model.FullName,
                            PhoneNumber = model.PhoneNumber,
                            Description = model.Description,
                            Email       = model.Email,
                            SessionId   = model.SessionId
                        },
                        Type = (ActivityLogParticipantTypes)model.Type
                    };

                    ActivityService.AddParticipantToSession(Session, model.SessionId, participant);

                    return(Json(new
                    {
                        Success = true,
                        Message = string.Empty,
                        Id = id
                    }));
                }
                catch (Exception e)
                {
                    MvcApplication.LogException(e);
                    return(Json(new
                    {
                        Success = false,
                        Message = "There was an error saving. It has been logged for later review.",
                        Id = 0
                    }));
                }
            }

            return(Json(new
            {
                Success = false,
                Message = "Invalid form",
                Id = 0
            }));
        }