Esempio n. 1
0
        public void AddClient(string firstname, string lastname, string secondname, int numbPassp, int serPassp, string phonenumber)
        {
            Passport passport = new Passport
            {
                number = numbPassp,
                series = serPassp
            };

            My.Passports.Add(passport);
            My.SaveChanges();

            int id = passport.Id;

            Client client = new Client
            {
                InBalckList = false,
                PassportId  = id,
                PhoneNumber = phonenumber,
                SecondName  = secondname,
                LastName    = lastname,
                FirstName   = firstname
            };


            My.Clients.Add(client);
            My.SaveChanges();

            int    idCl    = client.Id;
            Client checkRe = My.Clients.Where(k => k.PassportId == id).FirstOrDefault();
            Client check   = CheckedClient(checkRe, firstname, lastname, secondname, phonenumber);

            if (check != null)
            {
                MessageBox.Show("Пользователь успешно зарегистрирован");
            }
            else
            {
                try
                {
                    Passport pass = My.Passports.Where(k => k.Id == checkRe.PassportId).FirstOrDefault();
                    RemoveClient(checkRe.Id, pass.Id);
                }
                catch
                {
                }
                MessageBox.Show("Повторите попытку");
            }
        }
        public static bool Modificar(NotasCredito nota)
        {
            bool paso = false;

            try
            {
                Contex contex     = new Contex();
                var    estudiante = BLL.EstudiantesBLL.Buscar(nota.EstudianteID);
                var    notas      = Buscar(nota.NotasID);
                estudiante.Monto -= notas.Monto;
                BLL.EstudiantesBLL.Modificar(estudiante);

                contex.Entry(nota).State = EntityState.Modified;

                estudiante.Monto += nota.Monto;
                BLL.EstudiantesBLL.Modificar(estudiante);
                if (contex.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(paso);
        }
Esempio n. 3
0
        private void editButton_Click(object sender, EventArgs e)
        {
            int idClient = Convert.ToInt16(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value);

            Client client = My.Clients.Where(k => k.Id == idClient).FirstOrDefault();

            client.PhoneNumber = maskedTextBox1.Text;
            client.FirstName   = FirstNameBox.Text;
            client.LastName    = LastNameBox.Text;
            client.SecondName  = SecondNameBox.Text;

            int?     idPass   = client.PassportId;
            Passport passport = My.Passports.Where(k => k.Id == idPass).FirstOrDefault();

            passport.number = Convert.ToInt32(PassNumBox.Text);
            passport.series = Convert.ToInt16(PassSerBox.Text);

            My.SaveChanges();

            maskedTextBox1.Text = null;
            FirstNameBox.Text   = null;
            LastNameBox.Text    = null;
            SecondNameBox.Text  = null;
            PassNumBox.Text     = null;
            PassSerBox.Text     = null;

            button1_Click(sender, e);
        }
Esempio n. 4
0
        public void AddUser(AddUserBM user)
        {
            var userToAdd = Mapper.Map <User>(user);

            Contex.Users.Add(userToAdd);
            Contex.SaveChanges();
        }
Esempio n. 5
0
        public void RegisterUser(RegisterUserVM user)
        {
            var user1 = Mapper.Map <User>(user);

            Contex.Users.Add(user1);
            Contex.SaveChanges();
        }
Esempio n. 6
0
        public void Logout(string sessionId)
        {
            var session = Contex.Sessions.FirstOrDefault(x => x.SessionId == sessionId);

            session.IsActive = false;
            Contex.SaveChanges();
        }
Esempio n. 7
0
        //--------------------------------------------------------------------------------------------- // Добавление фильма
        public void AddMovie(string name, DateTime god, string category, ICollection <KinoSoft.MovieCountry> country, ICollection <KinoSoft.MovieProducer> producer, ICollection <KinoSoft.MovieActor> actor, ICollection <KinoSoft.MovieGenre> genre, string opisanie)
        {
            Movie movie = new Movie
            {
                Name        = name,
                Genres      = genre,
                Producers   = producer,
                Date        = god,
                Category    = category,
                Contries    = country,
                Actors      = actor,
                Description = opisanie
            };

            My.Movies.Add(movie);
            My.SaveChanges();
        }
Esempio n. 8
0
        public void AddSupplier(AddSupplierVM supplier, int userId)
        {
            var newSupp = Mapper.Map <Supplier>(supplier);

            Contex.Suppliers.Add(newSupp);
            Contex.SaveChanges();
            this.AddLog(userId, Operation.Add);
        }
Esempio n. 9
0
        public void AddCar(AddCarBM car, User user)
        {
            var carToAdd = Mapper.Map <AddCarBM, Car>(car);

            Contex.Cars.Add(carToAdd);
            Contex.SaveChanges();
            this.AddLog(user, Operation.Add, "Car");
        }
Esempio n. 10
0
        public void Add(AddCameraVM model, User user)
        {
            var camera = Mapper.Map <Models.Entity.Camera>(model);

            camera.User = user;

            Contex.Cameras.Add(camera);
            Contex.SaveChanges();
        }
Esempio n. 11
0
        public void RegisterStudent(ApplicationUser user)
        {
            var student     = new Student();
            var currentUser = Contex.Users.Find(user.Id);

            student.User = currentUser;
            Contex.Students.Add(student);
            Contex.SaveChanges();
        }
Esempio n. 12
0
        public void EditSupplier(EditSupplierBM model, int userId)
        {
            var supplier = Mapper.Map <Supplier>(model);

            Contex.Entry(supplier).State = EntityState.Modified;
            Contex.SaveChanges();

            this.AddLog(userId, Operation.Edit);
        }
Esempio n. 13
0
        public void SignOutStudentFromCourse(string courseName, string currentUser)
        {
            var course  = Contex.Courses.FirstOrDefault(x => x.Name == courseName);
            var student = Contex.Students.FirstOrDefault(x => x.User.Email == currentUser);

            course.Students.Remove(student);
            student.Courses.Remove(course);
            Contex.SaveChanges();
        }
Esempio n. 14
0
        public void Addpart(AddPartVM part)
        {
            var partToAdd = Mapper.Map <AddPartVM, Part>(part);
            var supplier  = Contex.Suppliers.Find(partToAdd.Supplier.Id);

            // supplier.Parts.Add(partToAdd);
            Contex.Parts.Add(partToAdd);
            Contex.SaveChanges();
        }
Esempio n. 15
0
        public void AddEmployee(string firstname, string lastname, string secondname, string phonenumber, string login, string password, int roleId, int passSer, int passNum)
        {
            Passport passport = new Passport
            {
                number = passNum,
                series = passSer
            };

            My.Passports.Add(passport);
            int id = passport.Id;

            My.Employees.Add(new Employee
            {
                FirstName   = firstname,
                LastName    = lastname,
                SecondName  = secondname,
                PhoneNumber = phonenumber,
                Login       = login,
                Password    = password,
                RoleId      = roleId,
                PassportId  = id
            });
            My.SaveChanges();
            Employee employee = My.Employees.Where(k => k.Login == login).FirstOrDefault();
            Employee check    = CheckedEmployee(employee, firstname, lastname, secondname, phonenumber, login, password, roleId, passNum, passSer);

            if (check != null)
            {
                MessageBox.Show("Пользователь успешно зарегистрирован");
            }
            else
            {
                try
                {
                    Passport pass = My.Passports.Where(k => k.Id == employee.PassportId).FirstOrDefault();
                    RemoveEmployee(employee.Id, pass.Id);
                }
                catch
                {
                }
                MessageBox.Show("Повторите попытку");
            }
        }
Esempio n. 16
0
        public void AddOrder(DateTime date, DateTime endDate, ArrayList arrayDisk, int idClient, int idOrder, int cost)
        {
            using (Contex My = new Contex())
            {
                My.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                Client client = My.Clients.Where(k => k.Id == idClient).FirstOrDefault();

                Order order = new Order
                {
                    Client   = client,
                    ClientId = idClient,
                    Date     = date,
                    EndDate  = endDate,
                    Status   = OrderStatus.Open,
                    Cost     = cost,
                    //Disks = arrayDisk1
                };
                My.Orders.Add(order);
                My.SaveChanges();
                //using (Contex db = new Contex())
                //{
                for (int i = 0; i < arrayDisk.Count; i++)
                {
                    int       diskId    = Convert.ToInt32(arrayDisk[i]);
                    Disk      disk      = My.Disks.Where(k => k.Id == diskId).FirstOrDefault();
                    int       orderId   = order.Id;
                    DiskOrder diskOrder = new DiskOrder    //add DiskOrder
                    {
                        Disk   = disk,
                        DiskId = diskId,
                        //Order = order,
                        //Order = My.Orders.Where(k => k.Id == orderId).FirstOrDefault(),
                        OrderId = orderId,
                    };
                    My.DiskOrders.Add(diskOrder);
                }
                My.SaveChanges();

                //My.SaveChanges();
            }
        }
Esempio n. 17
0
 public void AddNewCategory(AddNewCategoryBindingModel model)
 {
     if (!Contex.Categories.Any(x => x.Name == model.Name))
     {
         var category = new Category();
         category.Name   = model.Name;
         category.Topics = new List <Topic>();
         Contex.Categories.Add(category);
         Contex.SaveChanges();
     }
 }
Esempio n. 18
0
        private void AddLog(User user, Operation operation, string modifiedTable)
        {
            Log log = new Log()
            {
                User          = user,
                DateModified  = DateTime.Now,
                ModifiedTable = modifiedTable,
                Operation     = operation
            };

            Contex.Logs.Add(log);
            Contex.SaveChanges();
        }
Esempio n. 19
0
 public IActionResult YeniKullanici(Kullanici k)
 {
     if (ModelState.IsValid)
     {
         c.Kullanicis.Add(k);
         c.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("YeniKullanici"));
     }
 }
Esempio n. 20
0
        public void Create(CreateVM model)
        {
            var course = new Course()
            {
                Description = model.Description,
                Name        = model.Name,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate
            };

            Contex.Courses.Add(course);
            Contex.SaveChanges();
        }
Esempio n. 21
0
        public void AddLog(int userId, Operation operation)
        {
            User user = Contex.Users.Find(userId);
            Log  log  = new Log()
            {
                User          = user,
                DateModified  = DateTime.Now,
                ModifiedTable = "Suppliers",
                Operation     = operation
            };

            Contex.Logs.Add(log);
            Contex.SaveChanges();
        }
Esempio n. 22
0
 public IActionResult Kayit(ForumSoru f)
 {
     if (ModelState.IsValid)
     {
         string bil = HttpContext.Session.GetString("isUserLogin");
         f.kullanici = c.Kullanicis.Where(x => x.kullanıcıAd.Contains(bil)).FirstOrDefault();
         c.ForumSorus.Add(f);
         c.SaveChanges();
         return(RedirectToAction("Detail", f.Id));
     }
     else
     {
         return(RedirectToAction("Kayit"));
     }
 }
Esempio n. 23
0
        public void AddCustomer(AddCustomerBM customerBM)
        {
            var customer = Mapper.Map <AddCustomerBM, Customer>(customerBM);
            var age      = DateTime.Today.Year - customerBM.BirthDate.Year;

            if (age > 18)
            {
                customer.IsYoungDriver = false;
            }
            else
            {
                customer.IsYoungDriver = true;
            }
            Contex.Customers.Add(customer);
            Contex.SaveChanges();
        }
Esempio n. 24
0
        public void AddSale(AddSaleConfirmationBM sale)
        {
            var customer = Contex.Customers.FirstOrDefault(x => x.Name == sale.Customer);
            var carData  = sale.Car.Split();
            var carMake  = carData[0];
            var carModel = carData[1];
            var car      = Contex.Cars.FirstOrDefault(x => x.Make == carMake && x.Model == carModel);

            Contex.Sales.Add(new Sale()
            {
                Customer = customer,
                Car      = car,
                Discount = sale.Discount
            });
            Contex.SaveChanges();
        }
Esempio n. 25
0
        public void EditCustomer(EditCustomerBM customerBM)
        {
            var customer = Contex.Customers.Find(customerBM.Id);
            var age      = DateTime.Today.Year - customerBM.BirthDate.Year;

            if (age > 18)
            {
                customer.IsYoungDriver = false;
            }
            else
            {
                customer.IsYoungDriver = true;
            }
            customer.Name                = customerBM.Name;
            customer.BirthDate           = customerBM.BirthDate;
            Contex.Entry(customer).State = EntityState.Modified;
            Contex.SaveChanges();
        }
Esempio n. 26
0
        private void button3_Click(object sender, EventArgs e)
        {
            Employee emp  = My.Employees.Where(k => k.Login == loginBox.Text).FirstOrDefault();
            Passport pass = My.Passports.Where(k => k.Id == emp.PassportId).FirstOrDefault();
            Role     role = My.Roles.Where(k => k.RoleId == emp.RoleId).FirstOrDefault();

            emp.FirstName   = firstNameBox.Text;
            emp.LastName    = LastNameBox.Text;
            emp.SecondName  = secondNameBox.Text;
            emp.PhoneNumber = phoneNumberBox.Text;
            emp.Login       = loginBox.Text;
            emp.Password    = passwordBox.Text;
            pass.number     = Convert.ToInt32(numberBox.Text);
            pass.series     = Convert.ToInt32(seriesBox.Text);
            role.Name       = roleComboBox.Text;

            My.SaveChanges();
        }
        public static bool Guardar(NotasCredito Notas)
        {
            bool paso = false;

            try
            {
                Contex Contex     = new Contex();
                var    estudiante = BLL.EstudiantesBLL.Buscar(Notas.EstudianteID);
                estudiante.Monto += Notas.Monto;
                BLL.EstudiantesBLL.Modificar(estudiante);
                Contex.Notas.Add(Notas);
                Contex.SaveChanges();
                paso = true;
            }
            catch (Exception)
            {
                throw;
            }
            return(paso);
        }
Esempio n. 28
0
        public void Login(LoginBM user, string sessionId)
        {
            if (!this.Contex.Sessions.Any(login => login.SessionId == sessionId))
            {
                this.Contex.Sessions.Add(new Session()
                {
                    SessionId = sessionId
                });
                this.Contex.SaveChanges();
            }

            var session   = Contex.Sessions.FirstOrDefault(x => x.SessionId == sessionId);
            var userToLog = Contex.Users.FirstOrDefault(x => x.Username == user.Username && x.Password == user.Password);

            if (userToLog != null)
            {
                session.User     = userToLog;
                session.IsActive = true;

                Contex.SaveChanges();
            }
        }
Esempio n. 29
0
 public ActionResult Signup(User user)
 {
     ViewBag.title = "signup";
     if (ModelState.IsValid)
     {
         var output = db.users.FirstOrDefault(m => m.Email == user.Email);
         if (output == null)
         {
             db.users.Add(user);
             db.SaveChanges();
             ViewBag.Message     = user.Name + " Successfully Registested";
             TempData["message"] = user.Name + " Successfully Registested";
             ViewBag.danger      = false;
             return(RedirectToAction("Login", "Auth"));
             //return View();
         }
         ViewBag.Message     = user.Email + " Already Exist ! ";
         TempData["message"] = user.Email + " Already Exist ! ";
         ViewBag.danger      = true;
         return(View());
     }
     return(View());
 }
        public static bool Eliminar(int EstudianteId)
        {
            bool paso = false;

            try
            {
                Contex contex = new Contex();

                var nota       = contex.Notas.Find(EstudianteId);
                var estudiante = BLL.EstudiantesBLL.Buscar(nota.EstudianteID);
                estudiante.Monto -= nota.Monto;
                BLL.EstudiantesBLL.Modificar(estudiante);
                contex.Notas.Remove(nota);
                contex.SaveChanges();

                paso = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(paso);
        }