Exemplo n.º 1
0
        public UserController(DBcontext context)
        {
            _context = context;

            if (_context.Users.Count() == 0)
            {
                _context.Users.Add(new User {
                    FirstName = "Test"
                });
                _context.SaveChanges();
            }
        }
        public void addUser(UserDto user)
        {
            User newUser = new User()
            {
                firstName = user.firstName,
                lastName  = user.lastName,
                age       = user.age
            };

            _dbContext.Add(newUser);
            _dbContext.SaveChanges();
        }
Exemplo n.º 3
0
        public StableController(DBcontext context)
        {
            _context = context;

            if (_context.Stables.Count() == 0)
            {
                _context.Stables.Add(new Stable {
                    Name = "Test"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        private void RemoveManager()
        {
            var dep = DBcontext.Departments.Find(selectedDepId);

            dep.managerID = null;
            DBcontext.SaveChanges();

            ManagerOfSelectedDep = null;
            CancellProperties();
            AllDepWithManagerName = GetAllDepsWithManagerName();
            // MessageBox.Show("Руководитель смещен");
        }
Exemplo n.º 5
0
        public CategoryController(DBcontext context)
        {
            _context = context;

            if (_context.Categories.Count() == 0)
            {
                _context.Categories.Add(new Category {
                    Name = "Test"
                });
                _context.SaveChanges();
            }
        }
        public HorsesController(DBcontext context)
        {
            _context = context;

            if (_context.Horses.Count() == 0)
            {
                _context.Horses.Add(new Horse {
                    Name = "Test"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        private void UpdateDep()
        {
            var entity = DBcontext.Departments.Find(selectedDepId);

            entity.depName = DepName;
            if (_depManagerID == 0 && ManagerOfSelectedDep != null)
            {
                entity.managerID = _managerOfSelectedDep.empid;
            }
            DBcontext.SaveChanges();

            AllDepWithManagerName   = GetAllDepsWithManagerName();
            AllEmployeesWithDepName = GetEmployeersOfTheDep();
            CancellProperties();
        }
Exemplo n.º 8
0
        private void UpdateEmp()
        {
            var entity = DBcontext.Employees.Find(empPrimaryKey);

            entity.firstname   = FirstName;
            entity.lastname    = LastName;
            entity.patronymic  = Patronymic;
            entity.gender      = EmpGender;
            entity.dateOfBirth = BirthDate;
            entity.depID       = DepID;
            DBcontext.SaveChanges();

            AllDepWithManagerName = GetAllDepsWithManagerName();
            UpdateLinkedResources();
            CancelProperties();
        }
Exemplo n.º 9
0
        private void SaveNewEmp()
        {
            var newEmployee = new Employees(FirstName, LastName, Patronymic, EmpGender, BirthDate, DepID);

            if (EmpGender == 0)
            {
                MessageBox.Show("Нужно указать пол нового сотрудника");
            }
            else
            {
                DBcontext.Employees.Add(newEmployee);
                DBcontext.SaveChanges();

                UpdateLinkedResources();
                CancelProperties();
            }
        }
Exemplo n.º 10
0
        public ActionResult Routes(TransportRequestModel std)
        {
            //if (ModelState.IsValid)
            //{
            var advert = db.TransportRequests.ToList().Where(s => s.Id == std.Id).FirstOrDefault();

            advert.Notes = std.Notes;
            //advert.Pickup_Time = std.Pickup_Time;
            //advert.Delivery_Time = std.Delivery_Time;
            advert.Status = "Paid";

            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
            //}

            //return View();
        }
Exemplo n.º 11
0
        public ActionResult Edit(AdvertModel std)
        {
            if (ModelState.IsValid)
            {
                var advert = db.Adverts.ToList().Where(s => s.Id == std.Id).FirstOrDefault();
                advert.Description = std.Description;
                advert.Price       = std.Price;
                advert.Status      = std.Status;
                advert.Title       = std.Title;
                advert.Valid_from  = std.Valid_from;
                advert.Valid_to    = std.Valid_to;

                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
Exemplo n.º 12
0
 public IActionResult Add([FromForm] int?id)
 {
     if (id != null)
     {
         var      userid   = userManager.GetUserId(HttpContext.User);
         CartItem cartItem = new CartItem()
         {
             CustomerID = userid,
             AddDate    = DateTime.Now,
             ProductID  = Convert.ToInt32(id)
         };
         context.cartItems.Add(cartItem);
         context.SaveChanges();
     }
     else
     {
         ModelState.AddModelError("", "Something went wrong");
     }
     return(View("Index", "Product"));
 }
 private void btn_Them_Click(object sender, EventArgs e)
 {
     using (DBcontext db = new DBcontext())
     {
         var lst = db.NguyenLieux.ToList();
         foreach (NguyenLieu ln in lst)
         {
             if (ln.TenNL == tb_TenNL.Text.ToString())
             {
                 MessageBox.Show("Đã có nguyên liệu này mời thêm nguyên liệu khác");
                 return;
             }
         }
         int id = (int)this.dataGridViewNguyenLieu.CurrentRow.Cells[0].Value;
         db.NguyenLieux.Add(NguyenLieuDaChon(id));
         db.SaveChanges();
         MessageBox.Show("Thêm thành công");
         loaddulieu();
     }
 }
Exemplo n.º 14
0
        public ActionResult Register(User user)
        {
            DBcontext db = new DBcontext();

            if (ModelState.IsValid)
            {
                var check = db.Users.FirstOrDefault(s => s.Email == user.Email);
                if (check == null)
                {
                    user.PassWord = GetMD5(user.PassWord);
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ViewBag.error = "Email already exists";
                    return(View());
                }
            }
            return(View());
        }
Exemplo n.º 15
0
        public IActionResult NewUser(UserView uv)
        {
            int?userlevel = HttpContext.Session.GetInt32("IsAdmin");

            if (userlevel == null || userlevel == 0)
            {
                ModelState.AddModelError("Authorization Error", "You do not have authority to add user");
                return(RedirectToAction("LogOut"));
            }
            if (uv.password != uv.confirmpwd)
            {
                ModelState.AddModelError("password", "Confirmation Password must match the Password");
            }
            User userchk = _context.users.Where(e => e.email == uv.email).FirstOrDefault();

            if (userchk != null)
            {
                ModelState.AddModelError("email", "User with this email already exists");
            }
            if (ModelState.IsValid)
            {
                PasswordHasher <User> hasher = new PasswordHasher <User>();
                User user = new User();
                user.first_name = uv.first_name;
                user.last_name  = uv.last_name;
                user.email      = uv.email;
                user.password   = hasher.HashPassword(user, uv.password);
                user.created_at = DateTime.Now;
                user.updated_at = DateTime.Now;
                user.user_level = 0;
                _context.users.Add(user);
                _context.SaveChanges();
                return(RedirectToAction("Dashboard", "User"));
            }
            return(RedirectToAction("AddUser"));
        }
 public void addFeedback(Feedback f)
 {
     _dBcontext.Feedbacks.Add(f);
     _dBcontext.SaveChanges();
 }
Exemplo n.º 17
0
 public void Save()
 {
     context.SaveChanges();
 }
Exemplo n.º 18
0
 public void saveAllChanges()
 {
     _dbContext.SaveChanges();
 }
Exemplo n.º 19
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.UserID);
 }
 public void addEvent(Event e)
 {
     _dBcontext.Events.Add(e);
     _dBcontext.SaveChanges();
 }
 public void addEventResponse(EventResponse e)
 {
     _dBContext.EventResponses.Add(e);
     _dBContext.SaveChanges();
 }
Exemplo n.º 22
0
 public void Save()
 {
     g.SaveChanges();
 }
 public void addUser(User user)
 {
     _dBcontext.Users.Add(user);
     _dBcontext.SaveChanges();
 }