예제 #1
0
 private void btDeleteTelephone_Click(object sender, EventArgs e)
 {
     if (lvUserTelephone.SelectedItems.Count > 0)
     {
         var listViewItem = lvUserTelephone.SelectedItems[0];
         DeleteUserData.DeleteTelephone(listViewItem.SubItems[3].Text.GetInt());
         FillPhonesLv();
     }
     else
     {
         MessageContainer.DisplayError("Select telephone to delete", "Error");
     }
 }
예제 #2
0
 // functionality to delete selected address
 private void btDeleteAddress_Click(object sender, EventArgs e)
 {
     if (lvUserAddress.SelectedItems.Count > 0)
     {
         var listViewItem = lvUserAddress.SelectedItems[0];
         DeleteUserData.DeleteAddress(listViewItem.SubItems[3].Text.GetInt());
         FillAddressLv();
     }
     else
     {
         MessageContainer.DisplayError("Select address to delete", "Error");
     }
 }
예제 #3
0
        public static void ParseChannel(string filename)
        {
            try
            {
                var doc = new XmlDocument();
                doc.Load(filename);

                var xmlNodeList = doc.SelectNodes("/tv/channel");
                var rand        = new Random();

                if (xmlNodeList != null)
                {
                    var channelRepo = new BaseRepository <Channel>();
                    var channelList = (from XmlNode node in xmlNodeList
                                       where node.Attributes != null
                                       let originId = node.Attributes["id"].Value.GetInt()
                                                      select new Channel
                    {
                        Name = node.FirstChild.InnerText,
                        Price = rand.Next(0, rand.Next(1, 5) * 10),
                        IsAgeLimit = rand.Next(0, 4) % 2 == 0,
                        OriginalId = originId
                    }).ToList();
                    channelRepo.AddRange(channelList);

                    MessageContainer.ChannelsLoadGood();
                }
                else
                {
                    MessageContainer.SomethingWrongInFileLoad();
                }
            }
            catch (DbEntityValidationException ex)
            {
                var sb = new StringBuilder();
                foreach (var failure in ex.EntityValidationErrors)
                {
                    sb.Append($"{failure.Entry.Entity.GetType()} failed validation\n");
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.Append($"- {error.PropertyName} : {error.ErrorMessage}");
                        sb.AppendLine();
                    }
                }
                throw new DbEntityValidationException("Entity Validation Failed - errors follow:\n" + sb, ex);
            }
            catch (Exception ex)
            {
                MessageContainer.SomethingWrongInChannelLoad(ex);
            }
        }
예제 #4
0
        //behavior of passForm
        private void PassForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var eventSource = (Form)sender;

            if (eventSource.DialogResult != DialogResult.OK)
            {
                return;
            }
            CurrentUserId = UserIdDetect();

            if (CurrentUserId != 0)
            {
                return;
            }
            MessageContainer.DisplayError("Incorrect login or password", "Access denied");
            e.Cancel = true;
        }
예제 #5
0
        // the method saves newly-created user
        private void SaveAddedDetails()
        {
            var md5Hash  = MD5.Create();
            var userRepo = new BaseRepository <User>();

            userRepo.Insert(new User()
            {
                FirstName = tbFirstName.Text,
                LastName  = tbLastName.Text,
                Login     = tbLogin.Text,
                Password  = tbPassword.Text.GetMd5Hash(),
                UserType  = new BaseRepository <UserType>(userRepo.ContextDb)
                            .Get(x => x.TypeName == "Client").FirstOrDefault()
            });
            MessageContainer.DisplayInfo("Created new user successfully.\nYou may log in with new credentials.",
                                         "New user has been created");
        }
예제 #6
0
        // function searches a user in the db by id / login / id + login
        private void btSearch_Click(object sender, EventArgs e)
        {
            //check if search criteria have been entered
            if (tbSearchLogin.Text.Trim() == String.Empty &&
                tbSurname.Text.Trim() == String.Empty &&
                numSearchUserId.Value == 0)
            {
                MessageContainer.DisplayError("Please, set search criteria", "Error");
            }
            else
            {
                var foundUsers = new BaseRepository <User>().GetAll();

                // try to find by Name
                if (tbSearchName.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.FirstName == tbSearchName.Text.Trim());
                }

                // try to find by Surname
                if (tbSearchSurname.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.LastName == tbSearchSurname.Text.Trim());
                }

                // try to find by login
                if (tbSearchLogin.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.Login == tbSearchLogin.Text.Trim());
                }

                // try to find by Id
                if (numSearchUserId.Value != 0)
                {
                    foundUsers = foundUsers.Where(x => x.Id == numSearchUserId.Value);
                }

                if (!foundUsers.Any())
                {
                    MessageContainer.DisplayError("No users found according to selected criteria", "Error");
                    return;
                }
                FillUsersLv(foundUsers);
            }
        }
예제 #7
0
        public bool ValidateControls(int userId)
        {
            var errorMessage = "Error:";
            var isValidName  = true;

            if (tbFirstName.Text.Trim() != string.Empty && tbFirstName.Text.Trim().Length < 30)
            {
                if (!tbFirstName.Text.Trim().IsValidName())
                {
                    errorMessage += "\nFirst name should consist of English alphabet characters only.";
                    isValidName   = false;
                }
            }
            else
            {
                errorMessage += "\nFirst name should consist of up to 30 characters";
                isValidName   = false;
            }

            if (tbLastName.Text.Trim() != String.Empty | tbLastName.Text.Trim().Length <= 30)
            {
                if (!tbLastName.Text.Trim().IsValidName())
                {
                    errorMessage += "\nLast name should consist of English alphabet characters only.";
                    isValidName   = false;
                }
            }
            else
            {
                errorMessage += "\nLast name should consist of up to 30 characters";
                isValidName   = false;
            }

            if (isValidName)
            {
                SaveUpdatedDetails(userId);
            }
            else
            {
                MessageContainer.DisplayError(errorMessage, "Invalid input");
            }
            return(isValidName);
        }
예제 #8
0
        private void lvShowPrograms_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            //tv programme id in listview
            var id           = lvShowPrograms.Items[e.Index].SubItems[6].Text.GetInt();
            var userRepo     = new BaseRepository <User>();
            var scheduleRepo = new BaseRepository <UserSchedule>(userRepo.ContextDb);
            var user         = userRepo.Get(u => u.Id == CurrentUserId).FirstOrDefault();

            switch (e.NewValue)
            {
            case CheckState.Checked:
                if (scheduleRepo.GetAll().ToList().Find(s => s.TvShow.Id == id &&
                                                        s.User.Id == CurrentUserId) == null)
                {
                    var schedule = new UserSchedule
                    {
                        DueDate = DateTime.Now.AddDays(7),
                        User    = user,
                        TvShow  = new BaseRepository <TvShow>(userRepo.ContextDb)
                                  .Get(s => s.Id == id).FirstOrDefault()
                    };
                    scheduleRepo.Insert(schedule);
                }
                break;

            case CheckState.Unchecked:
                var removeSh = scheduleRepo.Get(x => x.TvShow.Id == id).FirstOrDefault();
                if (removeSh != null)
                {
                    scheduleRepo.Remove(removeSh);
                }
                break;

            case CheckState.Indeterminate:
                MessageContainer.DisplayError("Something went wrong in checking/unchecking tvShows (case CheckState.Indeterminate:)", "Error");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #9
0
        // validate email input
        public bool ValidateControls(int userId)
        {
            string errorMessage = "Error:";
            bool   isValidEmail = true;

            if (tbUserEmail.Text.Trim() != String.Empty && tbUserEmail.Text.Trim().Length < 50)
            {
                if (!tbUserEmail.Text.Trim().IsValidEmail())
                {
                    errorMessage += "\nPlease enter email in valid format";
                    isValidEmail  = false;
                }
                else if (tbUserEmail.Text.Trim().IsUniqueEmail())
                {
                    errorMessage += "\nEmail already exists. Please enter another one";
                    isValidEmail  = false;
                }
            }
            else
            {
                errorMessage += "\nEmail field cannot be empty or longer than 50 symbols";
                isValidEmail  = false;
            }

            if (!tbComment.Text.Trim().IsValidComment())
            {
                errorMessage += "\nComment cannot be longer than 500 characters";
                isValidEmail  = false;
            }

            if (isValidEmail)
            {
                SaveAddedDetails(userId);
            }
            else
            {
                MessageContainer.DisplayError(errorMessage, "Invalid input");
            }
            return(isValidEmail);
        }
예제 #10
0
        // validate number input
        public bool ValidateControls(int userId)
        {
            var errorMessage  = "Error:";
            var isValidNumber = true;

            if (tbNumber.Text.Trim() != String.Empty)
            {
                if (!tbNumber.Text.Trim().IsValidPhone())
                {
                    errorMessage += "\nPlease enter 5 to 9 phone number digits";
                    isValidNumber = false;
                }
                else if (tbNumber.Text.Trim().GetInt().IsUniqueNumber())
                {
                    errorMessage += "\nNumber already exists. Please enter another one";
                    isValidNumber = false;
                }
            }
            else
            {
                errorMessage += "\nNumber field cannot be empty";
                isValidNumber = false;
            }

            if (!tbComment.Text.Trim().IsValidComment())
            {
                errorMessage += "\nComment cannot be longer than 500 characters";
                isValidNumber = false;
            }

            if (isValidNumber)
            {
                SaveAddedDetails(userId);
            }
            else
            {
                MessageContainer.DisplayError(errorMessage, "Invalid input");
            }
            return(isValidNumber);
        }
예제 #11
0
        // method to change chosen user's type
        private void cbUserType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_userType)
            {
                var userRepo = new BaseRepository <User>();
                var user     = userRepo.Get(x => x.Id == _selectedUser)
                               .Include(x => x.UserType)
                               .First();

                // check if the user is active
                // in case he is not, show error message that it is forbidden to change type for inactive user
                if (user.IsActiveStatus)
                {
                    var newTypeId = (int)Enum.Parse(typeof(EUserType), cbUserType.SelectedItem.ToString());
                    var newType   = new BaseRepository <UserType>(userRepo.ContextDb)
                                    .Get(x => x.Id == newTypeId).FirstOrDefault();
                    if (newTypeId != user.UserType.Id &&
                        MessageBox.Show(@"Do you want to change user type from " + user.UserType.TypeName +
                                        @" to " + newType?.TypeName, @"Change user type",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        user.UserType = newType;
                        userRepo.Update(user);
                        MessageContainer.DisplayInfo("Next session for this user will start with new rights", "User type has been updated");
                    }
                    else
                    {
                        cbUserType.SelectedIndex = user.UserType.Id;
                    }
                }
                else
                {
                    _userType = true;
                    MessageContainer.DisplayError("Changing user type for inactive user is forbidden." +
                                                  Environment.NewLine + "Activate user first", "Error");
                    cbUserType.SelectedIndex = user.UserType.Id;
                }
                _userType = false;
            }
        }
예제 #12
0
 private void btUpdateTelephone_Click(object sender, EventArgs e)
 {
     if (lvUserTelephone.SelectedItems.Count > 0)
     {
         var listViewItem = lvUserTelephone.SelectedItems[0];
         UpdateUserDataForm updatePhone = new UpdateUserDataForm(listViewItem.SubItems[3].Text.GetInt(), UserDetailType.Telephone);
         updatePhone.Text = @"Update telephone";
         if (ParentForm != null)
         {
             ParentForm.Visible = false;
             if (updatePhone.ShowDialog() == DialogResult.OK)
             {
                 FillPhonesLv();
             }
             ParentForm.Visible = true;
         }
     }
     else
     {
         MessageContainer.DisplayError("Select address to update", "Error");
     }
 }
예제 #13
0
        // method checks all controls on the form once OK button has been pressed
        public bool ValidateControls()
        {
            var isValid      = true;
            var errorMessage = "Invalid input:";

            //validate first name
            if (tbFirstName.Text.Trim() == string.Empty)
            {
                errorMessage += "\nFirst name field is empty.";
                isValid       = false;
            }
            else if (!tbFirstName.Text.Trim().IsValidName())
            {
                errorMessage += "\nFirst name should consist of 2+ characters of English alphabet.";
                isValid       = false;
            }

            //validate last name
            if (tbLastName.Text.Trim() == string.Empty)
            {
                errorMessage += "\nLast name field is empty.";
                isValid       = false;
            }
            else if (!tbLastName.Text.Trim().IsValidName())
            {
                errorMessage += "\nLast name should consist of 2+ characters of English alphabet.";
                isValid       = false;
            }

            // validate login
            if (tbLogin.Text.Trim() == string.Empty |
                !tbLogin.Text.Trim().IsValidLoginAndPassword())
            {
                errorMessage += "\nLogin should consist of 2 to 20 of A-Z/a-z/0-9 characters.";
                isValid       = false;
            }
            else
            {
                if (tbLogin.Text.Trim().IsUniqueLogin())
                {
                    errorMessage += "\nUser already exists. Please, choose another login.";
                    isValid       = false;
                }
            }

            //validate password
            if (tbPassword.Text.Trim() == string.Empty | !(tbPassword.Text.Trim()).IsValidLoginAndPassword())
            {
                errorMessage += "\nPassword should be 2 to 20 of A-Z/a-z/0-9 symbols.";
                isValid       = false;
            }

            // show error message in case something is wrong with validation
            //otherwise, save new user details to the db
            if (isValid)
            {
                SaveAddedDetails();
            }
            else
            {
                tbPassword.Clear();
                MessageContainer.DisplayError(errorMessage, "User has not been created");
            }
            return(isValid);
        }
예제 #14
0
        public static void ParseProgramm(string filename)
        {
            try
            {
                var doc = new XmlDocument();
                doc.Load(filename);
                var xmlNodeList = doc.SelectNodes("/tv/programme");

                if (xmlNodeList != null)
                {
                    var rand = new Random();

                    var tvShowsRepo = new BaseRepository <TvShow>();
                    var channelsAll = new BaseRepository <Channel>(tvShowsRepo.ContextDb).GetAll().ToList();

                    var tvShowList = new List <TvShow>();

                    var progressBar = new ProgressForm();
                    progressBar.ShowDialog();
                    //id for progress bar
                    var id = 1;

                    //load channels to container
                    foreach (XmlNode node in xmlNodeList)
                    {
                        if (node.Attributes != null)
                        {
                            var channelOriginId = node.Attributes["channel"].Value.GetInt();
                            var shows           = new TvShow();
                            //{
                            shows.Name = node.FirstChild.InnerText;                                               //,
                            shows.Date = DateTime.ParseExact(node.Attributes["start"].Value,
                                                             "yyyyMMddHHmmss zzz", CultureInfo.InvariantCulture); //,
                            shows.IsAgeLimit          = rand.Next(0, 4) % 3 == 0;                                 //,
                            shows.CodeOriginalChannel = channelOriginId;                                          //,
                            shows.Channel             = channelsAll.Find(x => x.OriginalId == channelOriginId);
                            //};
                            tvShowList.Add(shows);
                        }
                        //count persents for progress bar
                        id++;
                        progressBar.ShowProgress(id, xmlNodeList.Count);
                    }

                    //-------------------------------------------------------------------------------------
                    //using BulkInsert approach to load big entity to DB (less than 0.5sec for 118000 entities)
                    //But, there is some problem:
                    //Channels in show link foreign key Channel_Id,
                    //but it is always '0' and Channels don't link with TvShow
                    //To utilize - tvShowsRepo.AddRange(tvShowList); - all in norm, but it takes too much time
                    //(more than 30 minutes)

                    //using (var ctx = tvShowsRepo.ContextDb)
                    //{
                    //    using (var transactionScope = new TransactionScope())
                    //    {
                    //        ctx.BulkInsert(tvShowList);
                    //        ctx.SaveChanges();
                    //        transactionScope.Complete();
                    //    }
                    //}

                    tvShowsRepo.AddRange(tvShowList);
                    //-------------------------------------------------------------------------------------

                    progressBar.Close();

                    MessageContainer.ProgrammsLoadGood();
                }
                else
                {
                    MessageContainer.SomethingWrongInFileLoad();
                }
            }
            catch (DbEntityValidationException ex)
            {
                var sb = new StringBuilder();

                foreach (var failure in ex.EntityValidationErrors)
                {
                    sb.Append($"{failure.Entry.Entity.GetType()} failed validation\n");
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.Append($"- {error.PropertyName} : {error.ErrorMessage}");
                        sb.AppendLine();
                    }
                }
                throw new DbEntityValidationException("Entity Validation Failed - errors follow:\n" + sb, ex);
            }
            catch (Exception ex)
            {
                MessageContainer.SomethingWrongInProgrammLoad(ex);
            }
        }
예제 #15
0
        internal static void ParseFavouriteMedia(string xmlFileName, int currentUserId)
        {
            var doc = new XmlDocument();

            doc.Load(xmlFileName);
            var xmlChannelsNodeList = doc.SelectNodes("tv/channel");
            var xmlTvShowsNodeList  = doc.SelectNodes("tv/programme");

            var channelRepo = new BaseRepository <Channel>();
            var tvShowRepo  = new BaseRepository <TvShow>(channelRepo.ContextDb);

            if (channelRepo.GetAll().Any() == false)
            {
                MessageContainer.DisplayInfo("You can't load favourite media. Channels table is clear!!!" +
                                             Environment.NewLine + "Load base about channels first!!!", "Error");
                return;
            }

            if (tvShowRepo.GetAll().Any() == false)
            {
                MessageContainer.DisplayInfo("You can't load favourite media. TV programmers table is clear!!!" +
                                             Environment.NewLine + "Load base about TvShows first!!!", "Error");
                return;
            }

            var currentUser = new BaseRepository <User>(channelRepo.ContextDb)
                              .Get(u => u.Id == currentUserId).FirstOrDefault();

            var orderChanellList = new List <OrderChannel>();
            var userScheduleList = new List <UserSchedule>();

            if (xmlChannelsNodeList != null || xmlTvShowsNodeList != null)
            {
                var userIdInFile = xmlChannelsNodeList?.Item(0)?.ChildNodes[2].InnerText.GetInt();
                if (userIdInFile != currentUserId)
                {
                    MessageContainer.DisplayError("This file include not your favourite media!!! Sorry", "Error");
                    return;
                }

                foreach (XmlNode chaNode in xmlChannelsNodeList)
                {
                    try
                    {
                        if (chaNode.Attributes == null || chaNode.Attributes["favourite"].Value != "true")
                        {
                            MessageContainer.DisplayError("This file doesn't contains favourite media!!!", "WRONG FILE!");
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        MessageContainer.DisplayError("This file doesn't contains favourite media!!!", "WRONG FILE!");
                        return;
                    }
                }

                //check for right format saved *.xml file (for programmers)
                if (xmlTvShowsNodeList != null &&
                    xmlTvShowsNodeList.Cast <XmlNode>().Any(showNode => showNode.Attributes == null ||
                                                            showNode.Attributes["favourite"].Value != "true"))
                {
                    MessageContainer.DisplayError("This file doesn't contains favourite media!!!", "WRONG FILE!");
                    return;
                }

                //add saved channels to list
                orderChanellList.AddRange(from XmlNode channelNode in xmlChannelsNodeList
                                          select channelNode.ChildNodes[0].InnerText.GetInt()
                                          into chanOrigId
                                          select new OrderChannel
                {
                    Channel = channelRepo.Get(ch => ch.OriginalId == chanOrigId).FirstOrDefault(),
                    User    = currentUser
                });


                if (xmlTvShowsNodeList != null)
                {
                    //add saved tvShows to list
                    userScheduleList.AddRange(from XmlNode tvShowNode in xmlTvShowsNodeList
                                              select tvShowNode.ChildNodes[0].InnerText.GetInt()
                                              into showId
                                              select new UserSchedule
                    {
                        User   = currentUser,
                        TvShow = tvShowRepo.Get(sh => sh.Id == showId).FirstOrDefault(),
                        //DueDate = currentOrder?.DueDate ?? DateTime.Now.AddDays(7)
                    });
                }

                if (orderChanellList.Any(o => o.Channel == null) ||
                    userScheduleList.Any(sc => sc.TvShow == null))
                {
                    MessageContainer.DisplayInfo("Saved channels or TV-programmers don't meet current database.", "Info");
                }
                else
                {
                    var ordChannelRepo = new BaseRepository <OrderChannel>(channelRepo.ContextDb);
                    ordChannelRepo.AddRange(orderChanellList);

                    var schedRepo = new BaseRepository <UserSchedule>(channelRepo.ContextDb);
                    schedRepo.AddRange(userScheduleList);

                    MessageContainer.DisplayInfo("Saved schedule was read good.", "Info");
                }
            }

            else
            {
                MessageContainer.SomethingWrongInFileLoad();
            }
        }
예제 #16
0
        public bool ValidateControls()
        {
            var errorMessage     = "Error(s):" + Environment.NewLine;
            var isValidCardDatas = true;

            mtbCardNumber.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
            var cardNumber = mtbCardNumber.Text.Trim();

            mtbCardNumber.TextMaskFormat = MaskFormat.IncludeLiterals;

            if (cardNumber == string.Empty || cardNumber.Length < 16)
            {
                errorMessage    += "Card number cannot be empty or shorter than 16 digits" + Environment.NewLine;
                isValidCardDatas = false;
            }

            int month;
            int year;

            int.TryParse(mtbDateCard.Text.Split('.').First().Trim(), out month);
            int.TryParse(mtbDateCard.Text.Split('.').Last().Trim(), out year);

            if (month <= 0 || month > 12 || year < (DateTime.Now.Year - 2000))
            {
                errorMessage    += $"Entered wrong month - '{month}' or year - '{year}'" + Environment.NewLine;
                isValidCardDatas = false;
            }

            int cvvCode;

            int.TryParse(mtbCvvCode.Text.Trim(), out cvvCode);
            if (mtbCvvCode.Text.Trim() == string.Empty || mtbCvvCode.Text.Trim().Length != 3)
            {
                errorMessage    += "CVV-code cannot be empty or length not than 3 digits" + Environment.NewLine;
                isValidCardDatas = false;
            }

            double summ;
            var    isDouble = double.TryParse(tbSummRecharge.Text, NumberStyles.AllowDecimalPoint,
                                              CultureInfo.InvariantCulture, out summ);

            if (isDouble == false || tbSummRecharge.Text.Trim() == string.Empty || summ <= 0.0)
            {
                errorMessage    += "Summ to recharge entered incorrect" + Environment.NewLine;
                isValidCardDatas = false;
            }

            if (isValidCardDatas)
            {
                var accountRepo = new BaseRepository <Account>();
                var userAcc     = accountRepo.Get(a => a.User.Id == CurrentUserId).FirstOrDefault();
                if (userAcc != null)
                {
                    userAcc.Balance += summ;
                    accountRepo.Update(userAcc);
                }
                else
                {
                    var user = new BaseRepository <User>(accountRepo.ContextDb)
                               .Get(u => u.Id == CurrentUserId).FirstOrDefault();

                    var newAccount = new Account
                    {
                        Balance        = summ,
                        Comment        = "automatically created new account",
                        IsActiveStatus = true,
                        User           = user
                    };
                    accountRepo.Insert(newAccount);
                }

                MessageContainer.DisplayInfo($"Your account was succesfull charged on {summ} UAH", "Succesfull");
            }
            else
            {
                MessageContainer.DisplayError(errorMessage, "Invalid input");
            }
            return(isValidCardDatas);
        }
예제 #17
0
        private void btMakeOrder_Click(object sender, EventArgs e)
        {
            var userRepo        = new BaseRepository <User>();
            var accountRepo     = new BaseRepository <Account>(userRepo.ContextDb);
            var orderRepo       = new BaseRepository <Order>(userRepo.ContextDb);
            var paymentRepo     = new BaseRepository <Payment>(userRepo.ContextDb);
            var ordChanRepo     = new BaseRepository <OrderChannel>(userRepo.ContextDb);
            var ordServicesRepo = new BaseRepository <OrderService>(userRepo.ContextDb);

            var user            = userRepo.Get(u => u.Id == CurrentUserId).FirstOrDefault();
            var balance         = accountRepo.Get(b => b.User.Id == CurrentUserId).FirstOrDefault();
            var notPaidChannels = ordChanRepo.Get(ch => ch.Order == null || ch.Order.IsPaid == false).ToList();
            var notPaidServices = ordServicesRepo.Get(s => s.Order == null || s.Order.IsPaid == false).ToList();

            if (notPaidServices.Count == 0 && notPaidChannels.Count == 0)
            {
                MessageContainer.DisplayError("No channels and/or services to pay", "Attention!!!");
                return;
            }

            if (balance?.IsActiveStatus == false)
            {
                MessageContainer.DisplayError("Account is diactivated!" + Environment.NewLine +
                                              "Please connect to administrator", "Attention!!!");
                return;
            }

            CurrentOrderId = GetNewOrderId(OrderPrice);
            //return order created in this method (by GetNewOrder)
            var order = orderRepo.Get(b => b.Id == CurrentOrderId).FirstOrDefault();

            if (balance != null && order != null && balance.Balance >= order.TotalPrice)
            {
                if (order.IsPaid)
                {
                    MessageContainer.DisplayInfo("Order is paid already", "Attention!!!");
                    return;
                }
                order.IsPaid     = true;
                order.DateOrder  = DateTime.Now;
                order.FromDate   = DateTime.Now;
                order.DueDate    = DateTime.Now.AddDays(7);
                order.User       = user;
                balance.Balance -= order.TotalPrice;

                orderRepo.Update(order);
                accountRepo.Update(balance);

                tbTotalPrice.Text     = @"0.00";
                tbAccountBalance.Text = balance.Balance.ToString(CultureInfo.CurrentCulture);

                var payment = new Payment()
                {
                    Id    = 1,
                    Date  = order.DateOrder,
                    Order = order,
                    Summ  = order.TotalPrice
                };

                paymentRepo.Insert(payment);

                var payingChannels = ordChanRepo.Get(ch => ch.User.Id == CurrentUserId &&
                                                     ch.Order == null).ToList();
                foreach (var chann in payingChannels)
                {
                    chann.Order   = order;
                    chann.Channel = chann.Channel;
                    ordChanRepo.Update(chann);
                }

                var payingServices = ordServicesRepo.Get(sr => sr.User.Id == CurrentUserId &&
                                                         sr.Order == null).ToList();
                foreach (var serv in payingServices)
                {
                    serv.Order             = order;
                    serv.AdditionalService = serv.AdditionalService;
                    ordServicesRepo.Update(serv);
                }

                MessageContainer.DisplayInfo(
                    $"Order #{order.Id} worth {order.TotalPrice} {lbUAH.Text}" +
                    $" was paid succesfully. {Environment.NewLine }" +
                    $"Total count of channels {order.OrderChannels?.Count ?? 0.00}",
                    @"Succesfull payment");
            }
            else
            {
                MessageContainer.DisplayError("Your balance is low!!!", "Error");
            }
        }