public ServiceMessage Update(ParticipantEditDTO participantEditDTO)
        {
            string message;
            bool   success = true;

            string oldName     = participantEditDTO.Name;
            string sportName   = participantEditDTO.SportName;
            string countryName = participantEditDTO.CountryName;

            string newName = participantEditDTO.NewParticipantName;

            try
            {
                ParticipantEntity participantEntity = unitOfWork.Participants.Get(oldName, sportName, countryName);
                if (participantEntity != null)
                {
                    participantEntity.Name = newName;
                    unitOfWork.Commit();

                    message = "Edited participant";
                }
                else
                {
                    message = "Such participant was not found";
                    success = false;
                }
            }
            catch (Exception ex)
            {
                message = ExceptionMessageBuilder.BuildMessage(ex);
                success = false;
            }

            return(new ServiceMessage(message, success));
        }
Example #2
0
        private void Edit(ParticipantDisplayModel participantDisplayModel, IEnumerable <string> countries, IEnumerable <string> sports)
        {
            ParticipantInfoViewModel viewModel = new ParticipantInfoViewModel(participantDisplayModel, sports, countries);
            ParticipantInfoControl   control   = new ParticipantInfoControl(viewModel);
            Window window = WindowFactory.CreateByContentsSize(control);

            viewModel.ParticipantEdited += (s, e) =>
            {
                ParticipantEditModel participantEditModel = e.Participant;
                ParticipantEditDTO   participantEditDTO   = Mapper.Map <ParticipantEditModel, ParticipantEditDTO>(participantEditModel);

                using (IParticipantService service = factory.CreateParticipantService())
                {
                    ServiceMessage serviceMessage = service.Update(participantEditDTO);
                    RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

                    if (serviceMessage.IsSuccessful)
                    {
                        window.Close();
                        Notify();
                    }
                }
            };

            window.Show();
        }