예제 #1
0
        public IActionResult Put(int id, [FromBody] Customer customer)
        {
            if (customer == null || customer.customer_id != id)
            {
                return(BadRequest());
            }

            _context.Customer.Update(customer);
            _context.SaveChanges();
            return(NoContent());
        }
예제 #2
0
        public IActionResult Put(int id, [FromBody] Lead lead)
        {
            if (lead == null || lead.lead_id != id)
            {
                return(BadRequest());
            }

            _context.Lead.Update(lead);
            _context.SaveChanges();
            return(NoContent());
        }
예제 #3
0
        public IActionResult Put(int id, [FromBody] Employee employee)
        {
            if (employee == null || employee.employee_id != id)
            {
                return(BadRequest());
            }


            _context.Employee.Update(employee);
            _context.SaveChanges();
            return(NoContent());
        }
예제 #4
0
        /// <summary>
        /// Создание нового клиента
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddClient_Click(object sender, EventArgs e)
        {
            var client = new Client();

            _formClient.Client           = client;
            _formClient.ClientLabel.Text = "Add Client";
            if (_formClient.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (!_formClient.Client.IsValid)
                    {
                        throw new Exception("Information filled incorrectly.");
                    }
                    using (var dataBase = new CRMContext())
                    {
                        dataBase.Clients.Add(_formClient.Client);
                        dataBase.SaveChanges();
                        ClientAdded?.Invoke(_formClient.Client, EventArgs.Empty);
                        tabControl1.SelectTab(tabClient);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Редактирование существующего клиента
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void EditClient_Click(object sender, EventArgs e)
 {
     try
     {
         var client = (clientListView.SelectedItems[0].Tag as Client);
         _formClient.Client           = client;
         _formClient.ClientLabel.Text = "Edit Client";
         if (_formClient.ShowDialog() == DialogResult.OK)
         {
             using (var dataBase = new CRMContext())
             {
                 Client tempClient = dataBase.Clients.Find(client.Id);
                 tempClient.Set(client);
                 //tempClient.Surname = client.Surname;
                 //tempClient.Name = client.Name;
                 //tempClient.BirthDate = client.BirthDate;
                 dataBase.SaveChanges();
                 ClientEdited?.Invoke(_formClient.Client, EventArgs.Empty);
             }
         }
     }
     catch
     {
         MessageBox.Show("Client not chosen.");
     }
 }
예제 #6
0
        /// <summary>
        /// Создание нового заказа
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddOrder_Click(object sender, EventArgs e)
        {
            var order = new Order();

            _formOrder.Order           = order;
            _formOrder.OrderLabel.Text = "Add Order";
            if (_formOrder.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (!_formOrder.Order.IsValid)
                    {
                        throw new Exception("Information filled not correctly.");
                    }
                    order.ClientId = order.Client.Id;
                    using (var dataBase = new CRMContext())
                    {
                        dataBase.Orders.Add(order);
                        dataBase.SaveChanges();
                        OrderAdded?.Invoke(order, EventArgs.Empty);
                        tabControl1.SelectTab(tabOrder);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Редактирование существующего клиента
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void EditOrder_Click(object sender, EventArgs e)
 {
     try
     {
         var order = (orderListView.SelectedItems[0].Tag as Order);
         _formOrder.Order           = order;
         _formOrder.OrderLabel.Text = "Edit Order";
         if (_formOrder.ShowDialog() == DialogResult.OK)
         {
             using (var dataBase = new CRMContext())
             {
                 Order tempOrder = dataBase.Orders.Find(order.Id);
                 tempOrder.Set(order);
                 //tempOrder.Sum = order.Sum;
                 //tempOrder.Client = order.Client;
                 //tempOrder.DateAndTime = order.DateAndTime;
                 //tempOrder.Status = order.Status;
                 dataBase.SaveChanges();
                 OrderEdited?.Invoke(_formOrder.Order, EventArgs.Empty);
             }
         }
     }
     catch
     {
         MessageBox.Show("Заказ не выбран.");
     }
 }
예제 #8
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (CRMContext dbContext = new CRMContext())
     {
         var task = new BD.CatalogTasks();
         task.Group = l_id_Copy.Text;
         task.Task  = l_id.Text;
         var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
         var context = new ValidationContext(task);
         if (!Validator.TryValidateObject(task, context, results, true))
         {
             foreach (var error in results)
             {
                 MessageBox.Show(error.ErrorMessage);
             }
         }
         else
         {
             try
             {
                 dbContext.CatalogTasks.Add(task);
                 dbContext.SaveChanges();
             }
             catch
             {
                 MessageBox.Show("Ошибка");
             }
         }
         if (Validator.TryValidateObject(task, context, results, true))
         {
             this.Close();
         }
     }
 }
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (CRMContext dbContext = new CRMContext())
     {
         status.Status = l_id.Text; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
         var context = new ValidationContext(status);
         if (!Validator.TryValidateObject(status, context, results, true))
         {
             foreach (var error in results)
             {
                 MessageBox.Show(error.ErrorMessage);
             }
         }
         else
         {
             try
             {
                 dbContext.Entry(status).State = System.Data.Entity.EntityState.Modified;
                 dbContext.SaveChanges();
             }
             catch
             {
                 MessageBox.Show("Ошибка!");
             }
         }
         if (Validator.TryValidateObject(status, context, results, true))
         {
             this.Close();
         }
     }
 }
예제 #10
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (CRMContext dbContext = new CRMContext())
            {
                var client = new BD.Clients();
                client.Name            = tb_name.Text;
                client.Address         = tb_address.Text;
                client.Phone           = tb_phone.Text;
                client.Email           = tb_email.Text;
                client.CheckingAccount = tb_checkingAccoubt.Text;
                client.Bank            = tb_bank.Text;
                client.Director        = tb_director.Text;
                client.Accountant      = tb_acccountant.Text;
                client.Info            = tb_info.Text;

                var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                var context = new ValidationContext(client);
                if (!Validator.TryValidateObject(client, context, results, true))
                {
                    foreach (var error in results)
                    {
                        MessageBox.Show(error.ErrorMessage);
                    }
                }
                else
                {
                    dbContext.Clients.Add(client);
                    dbContext.SaveChanges();
                }
                if (Validator.TryValidateObject(client, context, results, true))
                {
                    this.Close();
                }
            }
        }
예제 #11
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRMContext dbContext = new CRMContext())
                {
                    var manager = new BD.Managers();
                    manager.Name     = tb_name.Text;
                    manager.Login    = tb_login.Text;
                    manager.Password = Hash.EncryptPassword(tb_login.Text, tb_password.Text);
                    manager.Position = cb_position.SelectedItem.ToString();
                    manager.Group    = cb_group.SelectedItem.ToString();
                    manager.Address  = tb_address.Text;
                    manager.Phone    = tb_phone.Text;
                    manager.Passport = tb_passport.Text;
                    if (d_dateofbirth.SelectedDate >= (DateTime.Today).AddYears(18))
                    {
                        MessageBox.Show("Некорректный ввод даты рождения");
                    }
                    else
                    {
                        manager.DateOfBirth = d_dateofbirth.SelectedDate;
                    }
                    manager.DateRecruitment = d_daterecruitment.SelectedDate;
                    manager.Email           = tb_email.Text;
                    manager.Info            = tb_info.Text;

                    var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                    var context = new ValidationContext(manager);
                    if (!Validator.TryValidateObject(manager, context, results, true))
                    {
                        foreach (var error in results)
                        {
                            MessageBox.Show(error.ErrorMessage);
                        }
                    }
                    else
                    {
                        dbContext.Managers.Add(manager);
                        dbContext.SaveChanges();
                        EmailSender.SendMail("*****@*****.**", "w5323871w", manager.Email,
                                             "Регистрация", "Вы зарегистрировались в \"CRM - система\" \nВаш логин: " + manager.Login
                                             + "\nВаш пароль: " + tb_password.Text);
                    }
                    if (Validator.TryValidateObject(manager, context, results, true))
                    {
                        this.Close();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Ошибка! Некорректный ввод данных!");
            }
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (CRMContext dbContext = new CRMContext())
            {
                del_manager.Name  = tb_name.Text;
                del_manager.Login = tb_login.Text;
                if (tb_password.Text != null)
                {
                    del_manager.Password = Hash.EncryptPassword(tb_login.Text, tb_password.Text);
                }
                del_manager.Position = cb_position.SelectedItem.ToString();
                del_manager.Group    = cb_group.SelectedItem.ToString();
                del_manager.Address  = tb_address.Text;
                del_manager.Phone    = tb_phone.Text;
                del_manager.Passport = tb_passport.Text;
                if (del_manager.DateOfBirth >= (DateTime.Today).AddYears(18))
                {
                    MessageBox.Show("Некорректный ввод даты рождения");
                }
                else
                {
                    del_manager.DateOfBirth = d_dateofbirth.SelectedDate;
                }
                del_manager.DateRecruitment = d_daterecruitment.SelectedDate;
                del_manager.Email           = tb_email.Text;
                del_manager.Info            = tb_info.Text;

                var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                var context = new ValidationContext(del_manager);
                if (!Validator.TryValidateObject(del_manager, context, results, true))
                {
                    foreach (var error in results)
                    {
                        MessageBox.Show(error.ErrorMessage);
                    }
                }
                else
                {
                    try
                    {
                        dbContext.Entry(del_manager).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("Ошибка!");
                    }
                }
                if (Validator.TryValidateObject(del_manager, context, results, true))
                {
                    this.Close();
                }
            }
        }
예제 #13
0
 /// <summary>
 /// Удаление клиента из базы
 /// </summary>
 /// <param name="client"></param>
 private void DeleteClient(Client client)
 {
     using (var dataBase = new CRMContext())
     {
         Client tempClient = dataBase.Clients
                             .Where(o => o.Id == client.Id)
                             .FirstOrDefault();
         if (tempClient != null)
         {
             dataBase.Clients.Remove(tempClient);
             dataBase.SaveChanges();
         }
     }
 }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRMContext dbContext = new CRMContext())
                {
                    var position = new BD.CatalogPositions();
                    position.Position = l_position.Text;
                    if (l_pay.Text != "")
                    {
                        position.Pay = Convert.ToDecimal(l_pay.Text);
                    }
                    else
                    {
                        position.Pay = Convert.ToDecimal(1);
                    }

                    var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                    var context = new ValidationContext(position);
                    if (!Validator.TryValidateObject(position, context, results, true))
                    {
                        foreach (var error in results)
                        {
                            MessageBox.Show(error.ErrorMessage);
                        }
                    }
                    else
                    {
                        try
                        {
                            dbContext.CatalogPositions.Add(position);
                            dbContext.SaveChanges();
                        }
                        catch
                        {
                            MessageBox.Show("Ошибка");
                        }
                    }
                    if (Validator.TryValidateObject(position, context, results, true))
                    {
                        this.Close();
                    }
                }
                this.Close();
            }
            catch
            {
                MessageBox.Show("Неверно введены данные");
            }
        }
예제 #15
0
        /// <summary>
        /// Удаление заказа из базы
        /// </summary>
        /// <param name="order"></param>
        private void DeleteOrder(Order order)
        {
            using (var dataBase = new CRMContext())
            {
                Order tempOrder = dataBase.Orders
                                  .Where(o => o.Id == order.Id)
                                  .FirstOrDefault();

                if (tempOrder != null)
                {
                    dataBase.Orders.Remove(tempOrder);
                    dataBase.SaveChanges();
                }
            }
        }
예제 #16
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (CRMContext dbContext = new CRMContext())
     {
         var    group = new BD.CatalogGroupManagers();
         Random rnd   = new Random();
         try
         {
             int i = 1 + rnd.Next(10000);
             group.Group = l_id.Text;
             group.Id    = i;
         }
         catch (Exception)
         {
             MessageBox.Show("Повторите попытку");
         }
         var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
         var context = new ValidationContext(group);
         if (!Validator.TryValidateObject(group, context, results, true))
         {
             foreach (var error in results)
             {
                 MessageBox.Show(error.ErrorMessage);
             }
         }
         else
         {
             try
             {
                 dbContext.CatalogGroupManagers.Add(group);
                 dbContext.SaveChanges();
             }
             catch
             {
                 MessageBox.Show("Ошибка");
             }
         }
         if (Validator.TryValidateObject(group, context, results, true))
         {
             this.Close();
         }
     }
 }
예제 #17
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (del_obj != null)
         {
             using (CRMContext dbContext = new CRMContext())
             {
                 dbContext.Entry(del_obj).State = System.Data.Entity.EntityState.Deleted;
                 dbContext.SaveChanges();
             }
         }
         this.Close();
     }
     catch (Exception)
     {
         MessageBox.Show("Ошибка! Имеются записи, которые зависят от этой записи!");
     }
 }
예제 #18
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (CRMContext dbContext = new CRMContext())
            {
                var    task = new BD.Tasks();
                Random rnd  = new Random();
                try
                {
                    int i = 1 + rnd.Next(10000);
                    task.Id = i;
                }
                catch (Exception)
                {
                    MessageBox.Show("Повторите попытку");
                }
                task.Client       = l_client.Text;
                task.Manager      = l_manager.Text;
                task.Task         = l_task.Text;
                task.Info         = l_info.Text;
                task.Status       = l_status.Text;
                task.DateStart    = d_start.SelectedDate;
                task.DateComplete = d_complete.SelectedDate;

                var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                var context = new ValidationContext(task);
                if (!Validator.TryValidateObject(task, context, results, true))
                {
                    foreach (var error in results)
                    {
                        MessageBox.Show(error.ErrorMessage);
                    }
                }
                else
                {
                    dbContext.Tasks.Add(task);
                    dbContext.SaveChanges();
                }
                if (Validator.TryValidateObject(task, context, results, true))
                {
                    this.Close();
                }
            }
        }
예제 #19
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (CRMContext dbContext = new CRMContext())
            {
                del_task.Client       = l_client.Text;
                del_task.Manager      = l_manager.Text;
                del_task.Task         = l_task.Text;
                del_task.Info         = l_info.Text;
                del_task.Status       = l_status.Text;
                del_task.DateStart    = d_start.SelectedDate;
                del_task.DateComplete = d_complete.SelectedDate;

                var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                var context = new ValidationContext(del_task);
                if (!Validator.TryValidateObject(del_task, context, results, true))
                {
                    foreach (var error in results)
                    {
                        MessageBox.Show(error.ErrorMessage);
                    }
                }
                else
                {
                    try
                    {
                        dbContext.Entry(del_task).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("Ошибка!");
                    }
                }
                if (Validator.TryValidateObject(del_task, context, results, true))
                {
                    this.Close();
                }
            }
        }
예제 #20
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     using (CRMContext dbContext = new CRMContext())
     {
         foreach (var item in dbContext.Tasks)
         {
             dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted;
         }
         foreach (var item in dbContext.Managers)
         {
             if (item.Name != "Харсеко Никита Игоревич")
             {
                 dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted;
             }
         }
         foreach (var item in dbContext.Clients)
         {
             dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted;
         }
         dbContext.SaveChanges();
     }
 }