private Client CreateModel(ClientBindingModel model, Client client)
 {
     client.ClientFIO = model.ClientFIO;
     client.Email     = model.Email;
     client.Password  = model.Password;
     return(client);
 }
        public async Task <Client> AddClientAsync(ClientBindingModel clientModel)
        {
            var key = new byte[32];

            RNGCryptoServiceProvider.Create().GetBytes(key);
            var base64Secret = TextEncodings.Base64Url.Encode(key);

            var client = new Client
            {
                Id                   = Guid.NewGuid().ToString("D"),
                Active               = true,
                AllowedOrigin        = (string.IsNullOrWhiteSpace(clientModel.AllowedOrigin)) ? "*" : clientModel.AllowedOrigin,
                ApplicationType      = clientModel.ApplicationType,
                Name                 = clientModel.Name,
                RefreshTokenLifeTime = clientModel.RefreshTokenLifeTime,
                Secret               = base64Secret
            };

            this._context.Clients.Add(client);

            var result = await this._context.SaveChangesAsync() > 0;

            if (result)
            {
                return(client);
            }

            return(null);
        }
        public void CreateOrUpdate(ClientBindingModel model)
        {
            Client tempClient = model.Id.HasValue ? null : new Client
            {
                Id = 1
            };

            foreach (var Client in source.Clients)
            {
                if (Client.Email == model.Email && Client.Id != model.Id)
                {
                    throw new Exception("Уже есть клиент с таким логином");
                }
                if (!model.Id.HasValue && Client.Id >= tempClient.Id)
                {
                    tempClient.Id = Client.Id + 1;
                }
                else if (model.Id.HasValue && Client.Id == model.Id)
                {
                    tempClient = Client;
                }
            }
            if (model.Id.HasValue)
            {
                if (tempClient == null)
                {
                    throw new Exception("Элемент не найден");
                }
                CreateModel(model, tempClient);
            }
            else
            {
                source.Clients.Add(CreateModel(model, tempClient));
            }
        }
        public List <ClientViewModel> Read(ClientBindingModel model)
        {
            List <ClientViewModel> result = new List <ClientViewModel>();

            foreach (var client in source.Clients)
            {
                if (model != null)
                {
                    if (model.Id.HasValue)
                    {
                        if (client.Id == model.Id)
                        {
                            result.Add(CreateViewModel(client));
                            break;
                        }
                    }
                    else if (client.Email == model.Email && client.Password == model.Password)
                    {
                        result.Add(CreateViewModel(client));
                        break;
                    }
                    continue;
                }
                result.Add(CreateViewModel(client));
            }
            return(result);
        }
Exemplo n.º 5
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new Database())
     {
         Client element = model.Id.HasValue ? null : new Client();
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.Email          = model.Email;
         element.Login          = model.Login;
         element.Specialication = model.Specialication;
         element.Block          = model.Block;
         element.Password       = model.Password;
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new KursachDatabase())
     {
         Client element = model.Id.HasValue ? null : new Client();
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.Email       = model.Email;
         element.PhoneNumber = model.PhoneNumber;
         element.UserId      = model.UserId;
         element.Pasport     = model.Pasport;
         element.ClientFIO   = model.ClientFIO;
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new AbstractSweetShopDatabase())
     {
         Client element = context.Clients.FirstOrDefault(rec => rec.Email == model.Email && rec.Id != model.Id);
         if (element != null)
         {
             throw new Exception("Уже есть сотрудник с таким логином!");
         }
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Сотрудник не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
             element.IsAdmin = false;
         }
         element.ClientFIO = model.ClientFIO;
         element.Email     = model.Email;
         element.Password  = model.Password;
         context.SaveChanges();
     }
 }
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBoxName.Text))
     {
         MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (string.IsNullOrEmpty(textBoxPhonenumber.Text))
     {
         MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     try
     {
         ClientBindingModel client = new ClientBindingModel
         {
             Id          = Program.Client.Id,
             Email       = Program.Client.Email,
             Password    = Program.Client.Password,
             Nameclient  = textBoxName.Text,
             Phonenumber = textBoxPhonenumber.Text,
             Datebithday = dateTimePicker.Value,
             Status      = Program.Client.Status
         };
         _LogicC.CreateOrUpdate(client);
         Program.Client = _LogicC.Read(client)?[0];
         MessageBox.Show("Изменено", "Личные данные", MessageBoxButtons.OK, MessageBoxIcon.Information);
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 9
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new Database())
     {
         Client element = context.Clients.FirstOrDefault(rec => rec.FIO == model.FIO && rec.Id != model.Id);
         if (element != null)
         {
             throw new Exception("Уже есть клиент с таким ФИО");
         }
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.FIO            = model.FIO;
         element.DateBirthday   = model.DateBirthday;
         element.City           = model.City;
         element.PlaceResident  = model.PlaceResident;
         element.Phone          = model.Phone;
         element.TypeDocument   = model.TypeDocument;
         element.Series         = model.Series;
         element.NumberDocument = model.NumberDocument;
         element.Issued         = model.Issued;
         context.SaveChanges();
     }
 }
 public ClientViewModel GetElement(ClientBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var client = context.Clients
                      //.Include(x => x.Procedure).Include(x => x.Purchase).Include(x => x.Visit)
                      .FirstOrDefault(rec => rec.Login == model.Login ||
                                      rec.Id == model.Id);
         return(client != null ?
                new ClientViewModel
         {
             Id = client.Id,
             ClientName = client.ClientName,
             ClientSurame = client.ClientSurame,
             Login = client.Login,
             Password = client.Password,
             Mail = client.Mail,
             Tel = client.Tel
         } :
                null);
     }
 }
Exemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count == 1)
            {
                if (MessageBox.Show("Заблокировать пользователя?", "Потверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex).blocked = true;
                        var form = serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex);

                        ClientBindingModel element = new ClientBindingModel
                        {
                            id = form.id,
                            clientFirstName  = form.clientFirstName,
                            clientSecondName = form.clientSecondName,
                            number           = form.number,
                            mail             = form.mail,
                            password         = form.password,
                            blocked          = form.blocked
                        };

                        client.UpdElement(element);
                        MessageBox.Show("Пользователь заблокирован", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    LoadData();
                }
            }
        }
Exemplo n.º 12
0
 public List <ClientViewModel> Read(ClientBindingModel model)
 {
     using (var context = new AbstractSweetShopDatabase())
     {
         var result = context.Clients
                      .Where(rec => model == null || rec.Email.Equals(model.Email) && rec.Password.Equals(model.Password) ||
                             rec.Id == model.Id)
                      .Select(rec => new ClientViewModel
         {
             Id        = rec.Id,
             ClientFIO = rec.ClientFIO,
             Email     = rec.Email,
             Password  = rec.Password
         })
                      .ToList();
         if (result.Count() == 0)
         {
             return(null);
         }
         else
         {
             return(result);
         }
     }
 }
        public void CreateOrUpdate(ClientBindingModel model)
        {
            using (var context = new ElectronicsShopDatabase())
            {
                Client tempClient = model.Id.HasValue ? null : new Client();

                if (model.Id.HasValue)
                {
                    tempClient = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
                }

                if (model.Id.HasValue)
                {
                    if (tempClient == null)
                    {
                        throw new Exception("Элемент не найден");
                    }

                    CreateModel(model, tempClient);
                }
                else
                {
                    context.Clients.Add(CreateModel(model, tempClient));
                }

                context.SaveChanges();
            }
        }
 private void CheckData(ClientBindingModel model)
 {
     if (!Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"))
     {
         throw new Exception("В качестве логина должна быть указана почта");
     }
 }
Exemplo n.º 15
0
        private Client CreateModel(ClientBindingModel model, Client client, SchoolDataBase schoolDataBase)
        {
            if (model.Id.HasValue)
            {
                client.User.Login      = model.Login;
                client.User.Password   = model.Password;
                client.User.Name       = model.ClientName;
                client.User.Patronymic = model.ClientPatronymic;
                client.User.Surname    = model.ClientSurname;
                client.User.DateBirth  = model.DateBirth;
                schoolDataBase.SaveChanges();
                return(client);
            }
            User user = new User
            {
                Name       = model.ClientName,
                Surname    = model.ClientSurname,
                Patronymic = model.ClientPatronymic,
                DateBirth  = model.DateBirth,
                Login      = model.Login,
                Password   = model.Password,
            };

            schoolDataBase.Users.Add(user);
            schoolDataBase.SaveChanges();
            client.UserId = user.Id;
            return(client);
        }
Exemplo n.º 16
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count == 1)
            {
                try
                {
                    serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex).blocked = false;
                    var form = serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex);

                    ClientBindingModel element = new ClientBindingModel
                    {
                        id = form.id,
                        clientFirstName  = form.clientFirstName,
                        clientSecondName = form.clientSecondName,
                        number           = form.number,
                        mail             = form.mail,
                        password         = form.password,
                        blocked          = form.blocked,
                        sanction         = form.sanction
                    };

                    client.UpdElement(element);
                    MessageBox.Show("Пользователь разблокирован", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                LoadData();
            }
        }
Exemplo n.º 17
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new ZooDatabase())
     {
         Client elem = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
         if (model.Id.HasValue)
         {
             elem = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (elem == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             elem = new Client();
             context.Clients.Add(elem);
         }
         elem.Login       = model.Login;
         elem.ClientFIO   = model.ClientFIO;
         elem.Password    = model.Password;
         elem.BlockStatus = model.BlockStatus;
         context.SaveChanges();
     }
 }
Exemplo n.º 18
0
        public void CreateOrUpdate(ClientBindingModel model)
        {
            using (var context = new KorytoDatabase())
            {
                Client element = model.Id.HasValue ? null : new Client();

                if (model.Id.HasValue)
                {
                    element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);

                    if (element == null)
                    {
                        throw new Exception("Элемент не найден");
                    }
                }
                else
                {
                    element = new Client();
                    context.Clients.Add(element);
                }
                element.ClientFIO = model.ClientFIO;
                element.Password  = model.Password;
                element.Mail      = model.Mail == null ? element.Mail : model.Mail;
                element.Login     = model.Login == null ? element.Login : model.Login;
                context.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public void CreateOrUpdate(ClientBindingModel model)
        {
            var element = _clientStorage.GetElement(new ClientBindingModel
            {
                ClientName    = model.ClientName,
                ClientSurname = model.ClientSurname,
                Login         = model.Login,
                Password      = model.Password,
                Mail          = model.Mail,
                Tel           = model.Tel
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже есть клиент с такими данными");
            }
            if (model.Id.HasValue)
            {
                _clientStorage.Update(model);
            }
            else
            {
                _clientStorage.Insert(model);
            }
        }
Exemplo n.º 20
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new SecureShopDatabase())
     {
         Client element = context.Clients.FirstOrDefault(rec => rec.Email == model.Email && rec.Id != model.Id);
         if (element != null)
         {
             throw new Exception("Уже есть клиент с таким логином");
         }
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.Email     = model.Email;
         element.ClientFIO = model.ClientFIO;
         element.Password  = model.Password;
         context.SaveChanges();
     }
 }
Exemplo n.º 21
0
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new FurnitureFactoryDatabase())
     {
         Client element = model.Id.HasValue ? null : new Client();
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.FirstName   = model.FirstName;
         element.SecondName  = model.SecondName;
         element.Patronymic  = model.Patronymic;
         element.PhoneNumber = model.PhoneNumber;
         element.Email       = model.Email;
         element.Block       = model.Block;
         element.Password    = model.Password;
         context.SaveChanges();
     }
 }
Exemplo n.º 22
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count == 1)
            {
                if (MessageBox.Show("Начислить пользователю " + textBox2.Text + " штрафных баллов?", "Потверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex).sanction -= Convert.ToInt32(textBox2.Text);
                        var form = serviceClients.ElementAt(dataGridView.SelectedRows[0].Cells[0].RowIndex);

                        ClientBindingModel element = new ClientBindingModel
                        {
                            id = form.id,
                            clientFirstName  = form.clientFirstName,
                            clientSecondName = form.clientSecondName,
                            number           = form.number,
                            mail             = form.mail,
                            password         = form.password,
                            blocked          = form.blocked,
                            sanction         = form.sanction
                        };

                        client.UpdElement(element);
                        MessageBox.Show("Пользователю начислен штраф", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textBox2.Text = "";
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    LoadData();
                }
            }
        }
Exemplo n.º 23
0
        public void CreateOrUpdate(ClientBindingModel model)
        {
            Client element = source.Clients.FirstOrDefault(rec => rec.Email == model.Email && rec.Id != model.Id);

            if (element != null)
            {
                throw new Exception("Уже есть компонент с таким названием");
            }
            if (model.Id.HasValue)
            {
                element = source.Clients.FirstOrDefault(rec => rec.Id == model.Id);
                if (element == null)
                {
                    throw new Exception("Элемент не найден");
                }
            }
            else
            {
                int maxId = source.Clients.Count > 0 ? source.Clients.Max(rec => rec.Id) : 0;
                element = new Client {
                    Id = maxId + 1
                };
                source.Clients.Add(element);
            }
            element.Email     = model.Email;
            element.ClientFIO = model.ClientFIO;
            element.Password  = model.Password;
        }
Exemplo n.º 24
0
 public void Insert(ClientBindingModel model)
 {
     using (var context = new AutoServiceDatabase())
     {
         context.Clients.Add(CreateModel(model, new Client()));
         context.SaveChanges();
     }
 }
Exemplo n.º 25
0
 public void Insert(ClientBindingModel model)
 {
     using (var schoolDataBase = new SchoolDataBase())
     {
         schoolDataBase.Clients.Add(CreateModel(model, new Client(), schoolDataBase));
         schoolDataBase.SaveChanges();
     }
 }
Exemplo n.º 26
0
 private Client CreateModel(ClientBindingModel model, Client client)
 {
     client.FIO         = model.FIO;
     client.NumberPhone = model.NumberPhone;
     client.Email       = model.Email;
     client.Password    = model.Password;
     return(client);
 }
Exemplo n.º 27
0
 public void Insert(ClientBindingModel model)
 {
     using (var context = new HotelContext())
     {
         context.Client.Add(CreateModel(model, new Client()));
         context.SaveChanges();
     }
 }
Exemplo n.º 28
0
 private Client CreateModel(ClientBindingModel model, Client client)
 {
     client.Surname    = model.Surname;
     client.Name       = model.Name;
     client.Fathername = model.Fathername;
     client.Telephone  = model.Telephone;
     return(client);
 }
Exemplo n.º 29
0
 public void Insert(ClientBindingModel model)
 {
     using (var context = new stockContext())
     {
         context.Покупатель.Add(CreateModel(model, new Покупатель()));
         context.SaveChanges();
     }
 }
 public void Insert(ClientBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Clients.Add(CreateModel(model, new Client(), context));
         context.SaveChanges();
     }
 }