public void AddBanner(MainBanner banner)
 {
     using (_db)
     {
         _db.MainBanners.Add(banner);
         _db.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public void AddNewConverstion(Converstion convo)
 {
     using (_db)
     {
         _db.Converstions.Add(convo);
         _db.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void Adduser(User user)
 {
     using (_db)
     {
         _db.Entry(user.Role).State   = EntityState.Unchanged;
         _db.Entry(user.CityId).State = EntityState.Unchanged;
         _db.Users.Add(user);
         _db.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void AddProduct(Product product)
 {
     using (db)
     {
         db.Entry(product.Category).State = EntityState.Unchanged;
         db.Entry(product.User).State     = EntityState.Unchanged;
         db.Products.Add(product);
         db.SaveChanges();
     }
 }
        public ActionResult Create([Bind(Include = "ID,Name")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                db.Subjects.Add(subject);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(subject));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,Text,Score,RightAnswer,QuestionID")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                db.Answers.Add(answer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(answer));
        }
        public ActionResult Create([Bind(Include = "ID,Name")] UserType userType)
        {
            if (ModelState.IsValid)
            {
                db.UserTypes.Add(userType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userType));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ID,UserID,SubjectID")] UserSubject userSubject)
        {
            if (ModelState.IsValid)
            {
                db.UserSubjects.Add(userSubject);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userSubject));
        }
Exemplo n.º 9
0
 public void AddCamera(Camera camera)
 {
     using (db)
     {
         db.Entry(camera.Brand).State       = EntityState.Unchanged;
         db.Entry(camera.Series).State      = EntityState.Unchanged;
         db.Entry(camera.Category).State    = EntityState.Unchanged;
         db.Entry(camera.SubCategory).State = EntityState.Unchanged;
         db.Cameras.Add(camera);
         db.SaveChanges();
     }
 }
        public void Test1()
        {
            var SqLite    = new SqliteConnection("Filename=:memory:");
            var DBOptions = new DbContextOptionsBuilder <DBContextClass>().UseSqlite(SqLite).Options;

            SqLite.Open();
            using (var db = new DBContextClass(DBOptions))
            {
                db.Database.Migrate();
                var clients = new Client();
                clients.FName    = "John";
                clients.LName    = "Smith";
                clients.UserName = "******";
                clients.Password = "******";
                db.Add(clients);
                db.SaveChanges();
            }
            using (var db = new DBContextClass(DBOptions))
            {
                var clients = db.Clients
                              .Where(b => b.FName == "John")
                              .OrderBy(b => b.ClientID)
                              .ToList()
                              .First();
                Assert.Equal("John", clients.FName);
            }
        }
Exemplo n.º 11
0
 public void AddOrder(FinalOrder order)
 {
     using (_db)
     {
         _db.FinalOrders.Add(order);
         _db.SaveChanges();
     }
 }
        public void AddCountry(Country country)
        {
            DBContextClass db = new DBContextClass();

            using (db)
            {
                db.Countries.Add(country);
                db.SaveChanges();
            }
        }
Exemplo n.º 13
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,userID,Text")] Question question)
        {
            ViewBag.answerNames  = Request.Form.GetValues("the_answer");
            ViewBag.answerScores = Request.Form.GetValues("Score");
            ViewBag.rightAnswer  = Request.Form.Get("right_answer");
            // string QuestionText = Request.Form.Get("Question");
            if (!String.IsNullOrEmpty(question.Text))
            {
                //Add the Question
                Question question2 = new Question();
                question2.Text = question.Text;
                db.Questions.Add(question2);
                db.SaveChanges();

                //Get Question ID
                ViewBag.QuestioniID = question2.ID;


                //Add Answers to the Question
                for (int i = 0; i < ViewBag.answerNames.Length; i++)
                {
                    if (!String.IsNullOrEmpty(ViewBag.answerNames[i]))
                    {
                        Answer answerObject = new Answer();
                        answerObject.QuestionID = question2.ID;
                        answerObject.Score      = Convert.ToInt32(ViewBag.answerScores[i]);
                        answerObject.Text       = ViewBag.answerNames[i];

                        //We suppuse that first answer is right answer
                        if (i == 0)//ViewBag.rightAnswer == "on"
                        {
                            answerObject.RightAnswer = 1;
                        }

                        db.Answers.Add(answerObject);
                        db.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Index"));
            // return View(question2);
        }
        public void AddCity(City city)
        {
            DBContextClass db = new DBContextClass();

            using (db)
            {
                db.Entry(city.Country).State = EntityState.Unchanged;
                db.Cities.Add(city);
                db.SaveChanges();
            }
        }
        public void DeleteCountry(Country country)
        {
            DBContextClass db = new DBContextClass();

            using (db)
            {
                db.Entry(country).State = EntityState.Deleted;
                db.Countries.Remove(country);
                db.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public ActionResult Create([Bind(Include = "ID,Name,Email,Password,ConfirmPassword,Gender,DateOfBirth,Address,PhoneNumber,UserTypeID")] User user)
        {
            if (ModelState.IsValid)
            {
                if (db.Users.Any(x => x.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "User Email is already exist");
                    // Response.Write("Error:<br/><font color='red'>User Email is already exist</font>");
                }
            }

            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }