예제 #1
0
        public IActionResult Customers(Customers customers)
        {
            if (ModelState.IsValid)
            {
                customers.CustomerId = GenerateAutoId(4);
                _dbContext.Customers.Add(customers);
                _dbContext.SaveChanges();

                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
        public ActionResult Delete(String id)
        {
            try
            {

                using (var dbContext = new NORTHWNDContext())
                {
                    Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First();
                    if (customer == null)
                    {
                        ViewBag.ErrorMessage = "User was not found";
                    }
                    else
                    {
                        dbContext.Customers.Remove(customer);
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {

                throw new ArgumentException(ex.Message);
            }
            return RedirectToAction("Index", "Default");
        }
예제 #3
0
        public bool Post([FromBody] EmployeeModel newEmployee)
        {
            var success = false;

            try
            {
                var newDBEmployee = new Employee();
                newDBEmployee.FirstName = newEmployee.Name;
                newDBEmployee.LastName  = newEmployee.LastName;
                newDBEmployee.HomePhone = newEmployee.Phone;

                dbContext.Employees.Add(newDBEmployee);
                dbContext.SaveChanges();
                success = true;
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(success);
        }
예제 #4
0
        public void Post([FromBody] UserModel newUser)
        {
            var userInDB = new User();

            userInDB.UserName     = newUser.UserName;
            userInDB.CreationDate = DateTime.Now;
            userInDB.UserId       = Guid.NewGuid();
            userInDB.Salt         = Guid.NewGuid().ToString();

            userInDB.PasswordHash = Encrypt(userInDB.Salt, newUser.Password);

            dataContext.Users.Add(userInDB);
            dataContext.SaveChanges();
        }
 /// <summary>
 ///     Insert entity
 /// </summary>
 /// <param name="entity">Entity</param>
 public T Insert(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     entity = _entities.Add(entity).Entity;
     _context.SaveChanges();
     return(entity);
 }
 public ActionResult Create(CustomerModel cusModel)
 {
     try
     {
         using (var dbContext = new NORTHWNDContext())
         {
             Customer customer = Mapper.CustomerModelToEntity(cusModel);
             dbContext.Customers.Add(customer);
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new ArgumentException(ex.Message);
     }
     return(RedirectToAction("Index", "Default"));
 }
예제 #7
0
        public object GetEmployees(int employeeId)
        {
            var transaction = DataContext.Database.BeginTransaction();

            try
            {
                var employees = DataContext.Employees.FirstOrDefault(f => f.EmployeeId == employeeId);
                employees.FirstName = "Nancy";
                //employees.FirstName = "Pr " + employeeId + ".";
                DataContext.SaveChanges();
                transaction.Commit();
                return(employees);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                return(null);
            }
        }
        public ActionResult Create(CustomerModel cusModel)
        {
            try
            {
                using (var dbContext = new NORTHWNDContext())
                {
                    Customer customer = Mapper.CustomerModelToEntity(cusModel);
                    dbContext.Customers.Add(customer);
                    dbContext.SaveChanges();

                }

            }
            catch (Exception ex)
            {

                throw new ArgumentException(ex.Message);
            }
            return RedirectToAction("Index", "Default");
        }
 public ActionResult Delete(String id)
 {
     try
     {
         using (var dbContext = new NORTHWNDContext())
         {
             Customer customer = dbContext.Customers.Where(o => o.CustomerID == id).First();
             if (customer == null)
             {
                 ViewBag.ErrorMessage = "User was not found";
             }
             else
             {
                 dbContext.Customers.Remove(customer);
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw new ArgumentException(ex.Message);
     }
     return(RedirectToAction("Index", "Default"));
 }
 public ActionResult Edit(CustomerModel cusModel)
 {
     try
     {
         using (var dbContext = new NORTHWNDContext())
         {
             Customer customer = dbContext.Customers.Where(o => o.CustomerID == cusModel.CustomerID).First();
             if (customer == null)
             {
                 ViewBag.ErrorMessage = "User was not found";
             }
             else
             {
                 customer = Mapper.UpdateCustomerModelToEntity(customer, cusModel);
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw new ArgumentException(ex.Message);
     }
     return(RedirectToAction("Index", "Default"));
 }
예제 #11
0
 public void Save()
 {
     _context.SaveChanges();
     _nwndContext.SaveChanges();
 }
예제 #12
0
 public void SaveChange()
 {
     _context.SaveChanges();
 }
        public ActionResult Edit(CustomerModel cusModel)
        {
            try
            {

                using (var dbContext = new NORTHWNDContext())
                {
                    Customer customer = dbContext.Customers.Where(o => o.CustomerID == cusModel.CustomerID).First();
                    if (customer == null)
                    {
                        ViewBag.ErrorMessage = "User was not found";
                    }
                    else
                    {
                        customer = Mapper.UpdateCustomerModelToEntity(customer, cusModel);
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {

                throw new ArgumentException(ex.Message);
            }
            return RedirectToAction("Index", "Default");
        }
예제 #14
0
 public void SaveChanges()
 {
     _dbContext.SaveChanges();
 }
예제 #15
0
 public int Update(Product session)
 {
     _context.Entry(session).State = EntityState.Modified;
     return(_context.SaveChanges());
 }
예제 #16
0
 public void Add(Products product)
 {
     _context.Products.Add(product);
     _context.SaveChanges();
 }
 public void Add(Customers customer)
 {
     _context.Customers.Add(customer);
     _context.SaveChanges();
 }
예제 #18
0
 public IActionResult Index(Customers customer)
 {
     _context.Customers.Add(customer);
     _context.SaveChanges();
     return(View());
 }