Esempio n. 1
0
        public ServiceMessage Update(BookmakerEditDTO bookmakerEditDTO, string login)
        {
            string message = "";
            bool   success = true;

            if (success = Validate(bookmakerEditDTO, ref message))
            {
                try
                {
                    int             id = unitOfWork.Users.GetIdByLogin(login);
                    BookmakerEntity bookmakerEntity = unitOfWork.Bookmakers.Get(id);

                    bookmakerEntity.FirstName   = bookmakerEditDTO.FirstName;
                    bookmakerEntity.LastName    = bookmakerEditDTO.LastName;
                    bookmakerEntity.PhoneNumber = bookmakerEditDTO.PhoneNumber;

                    unitOfWork.Commit();

                    message = "Edited bookmaker's info";
                }
                catch (Exception ex)
                {
                    message = ExceptionMessageBuilder.BuildMessage(ex);
                    success = false;
                }
            }

            return(new ServiceMessage(message, success));
        }
        private void Edit(BookmakerDisplayModel bookmakerDisplayModel)
        {
            BookmakerEditModel bookmakerEditModel = Mapper.Map <BookmakerDisplayModel, BookmakerEditModel>(bookmakerDisplayModel);

            BookmakerInfoViewModel viewModel = new BookmakerInfoViewModel(bookmakerEditModel);
            BookmakerInfoControl   control   = new BookmakerInfoControl(viewModel);
            Window window = WindowFactory.CreateByContentsSize(control);

            viewModel.BookmakerEdited += (s, e) =>
            {
                bookmakerEditModel = e.Bookmaker;
                BookmakerEditDTO bookmakerEditDTO = Mapper.Map <BookmakerEditModel, BookmakerEditDTO>(bookmakerEditModel);

                using (IBookmakerService service = factory.CreateBookmakerService())
                {
                    ServiceMessage serviceMessage = service.Update(bookmakerEditDTO, bookmakerDisplayModel.Login);
                    RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

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

            window.Show();
        }
Esempio n. 3
0
        private bool Validate(BookmakerEditDTO bookmakerEditDTO, ref string message)
        {
            bool isValid = true;

            if (String.IsNullOrEmpty(bookmakerEditDTO.LastName))
            {
                message = "Last name must not be empty";
                isValid = false;
            }
            else if (String.IsNullOrEmpty(bookmakerEditDTO.FirstName))
            {
                message = "First name must not be empty";
                isValid = false;
            }
            else if (String.IsNullOrEmpty(bookmakerEditDTO.PhoneNumber))
            {
                message = "Phone number name must not be empty";
                isValid = false;
            }

            return(isValid);
        }