Beispiel #1
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmployeeID)
            {
                return(BadRequest());
            }

            db.Entry(employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.PId)
            {
                return(BadRequest());
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public IHttpActionResult PutBook(string id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.Title)
            {
                return(BadRequest());
            }

            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutUsuarios(int id, Usuarios usuarios)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != usuarios.id)
            {
                return(BadRequest("Los Ids deben ser iguales para realizar la actualizacion."));
            }

            db.Entry(usuarios).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsuariosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(usuarios));
        }
        //put-update database on id
        public IHttpActionResult PutCustomer(CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("This is invalid model.please recheck"));
            }
            using (var x = new webapiEntities())
            {
                var checkExsitingCustomer = x.Customers.Where(c => c.id == customer.Id)
                                            .FirstOrDefault <Customer>();
                if (checkExsitingCustomer != null)
                {
                    checkExsitingCustomer.name    = customer.Name;
                    checkExsitingCustomer.address = customer.Address;
                    checkExsitingCustomer.phone   = customer.Phone;
                    x.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
 //delete-delete a record base on id
 public IHttpActionResult Delete(int id)
 {
     if (id <= 0)
     {
         return(BadRequest("please enter valid customer id"));
     }
     using (var x = new webapiEntities())
     {
         var customer = x.Customers
                        .Where(c => c.id == id).FirstOrDefault();
         x.Entry(customer).State = System.Data.Entity.EntityState.Deleted;
         x.SaveChanges();
     }
     return(Ok());
 }
        //post-insert new record
        public IHttpActionResult PostNewCustomer(CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invaliddata.please recheck"));
            }
            using (var x = new webapiEntities())
            {
                x.Customers.Add(new Customer()
                {
                    name    = customer.Name,
                    email   = customer.Email,
                    address = customer.Address,
                    phone   = customer.Phone
                });
                x.SaveChanges();
            }

            return(Ok());
        }
        public int Login(ChromeDriver chromeDriver, WebDriverWait wait, string userName, string passWord)
        {
            chromeDriver.Url = "http://qldt.actvn.edu.vn/CMCSoft.IU.Web.info/Login.aspx";
            chromeDriver.Navigate();
            string source = chromeDriver.PageSource;
            // tìm username input
            var userNameInput = chromeDriver.FindElementById("txtUserName");

            userNameInput.SendKeys(userName);
            // tìm password input
            var passWordInput = chromeDriver.FindElementById("txtPassword");

            passWordInput.SendKeys(passWord);
            // tìm nust login
            var btnSubmit = chromeDriver.FindElementById("btnSubmit");

            btnSubmit.Click();
            chromeDriver.FindElement(By.Id("PageHeader1_lblUserRole"));
            wait.Until(driver => driver.FindElement(By.Id("PageHeader1_lblUserRole")).Displayed);
            string currentURL = chromeDriver.Url;

            if (currentURL.ToLower() != "http://qldt.actvn.edu.vn/CMCSoft.IU.Web.info/home.aspx".ToLower())
            {
                //Không đăng nhập thành công(tài khoản mật khẩu sai)
                return(-1);
            }
            else
            {
                if (CheckExistAccount(userName, passWord) == -1)
                {
                    #region Vào cái trang thông tin cá nhân này lấy ít thông tin
                    //http://qldt.actvn.edu.vn/CMCSoft.IU.Web.Info/StudentViewExamList.aspx
                    chromeDriver.Url = "http://qldt.actvn.edu.vn/CMCSoft.IU.Web.info/StudentMark.aspx";
                    string hoTen = chromeDriver.FindElementById("lblStudentName").Text;
                    string khoa  = chromeDriver.FindElementById("lblAy").Text;
                    string lop   = chromeDriver.FindElementById("lblAdminClass").Text;
                    #endregion
                    #region Save Student
                    sinhVien sV = new sinhVien();
                    sV.userName = userName;
                    sV.passWord = passWord;
                    sV.lop      = lop;
                    sV.khoa     = lop;
                    sV.ten      = hoTen;
                    con.sinhViens.Add(sV);
                    con.SaveChanges();
                    #endregion
                    return(2);
                }
                else if (CheckExistAccount(userName, passWord) == 0)
                {
                    return(0);
                }
                else
                {
                    sinhVien sV = con.sinhViens.Where(x => x.userName == userName).FirstOrDefault();
                    sV.passWord = passWord;
                    con.SaveChanges();
                    return(1);
                }
            }
        }
Beispiel #9
0
 public void Save()
 {
     _context.SaveChanges();
 }