Ejemplo n.º 1
0
        public void saveToFile(string input, string des)
        {
            if (des.Equals("input"))
            {
                var todo = dbContext.InputDataModels.SingleOrDefault();
                dbContext.InputDataModels.Remove(todo);
                dbContext.SaveChanges();

                InputDataModel data = new InputDataModel();
                data.Input = input;

                dbContext.InputDataModels.Add(data);
                dbContext.SaveChanges();
            }
            else
            {
                var todo = dbContext.AlphabetizedDataModels.SingleOrDefault();
                dbContext.AlphabetizedDataModels.Remove(todo);
                dbContext.SaveChanges();

                AlphabetizedDataModel data = new AlphabetizedDataModel();
                data.Alphabetized = input;

                dbContext.AlphabetizedDataModels.Add(data);
                dbContext.SaveChanges();
            }
        }
        public ActionResult Create([Bind(Include = "ID,Name,Accounted,Encrypted,Production")] DBdata dBdata)
        {
            if (ModelState.IsValid)
            {
                db.Dbset.Add(dBdata);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dBdata));
        }
Ejemplo n.º 3
0
        public ActionResult Create(Category model)
        {
            int categoryId = (from Category in dBContext.Categories
                              where model.CategoryName.Equals(Category.CategoryName)
                              select Category.CategoryId).FirstOrDefault();

            if (categoryId != 0)
            {
                return(Json("Failure", JsonRequestBehavior.AllowGet));
            }


            dBContext.Categories.Add(model);
            dBContext.SaveChanges();
            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public ActionResult Create(Product model)
        {
            int productId = (from product in dBContext.Products
                             where model.ProductName.Equals(product.ProductName)
                             where model.CategoryId.Equals(product.CategoryId)
                             select product.ProductId).FirstOrDefault();

            if (productId != 0)
            {
                return(Json("Failure", JsonRequestBehavior.AllowGet));
            }


            dBContext.Products.Add(model);
            dBContext.SaveChanges();
            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public ActionResult <string> Register(string email, string password, string nickname)
        {
            var uuid = Guid.NewGuid().ToString();
            var info = dbContext.Users.Where(n => n.NickName.Equals(nickname)).ToList().FirstOrDefault();

            if (info != null)
            {
                return(Ok(new
                {
                    status = false,
                    msg = "昵称重复"
                }));
            }

            dbContext.Users.Add(new DBModel.User {
                UserId = uuid, NickName = nickname
            });
            dbContext.SaveChanges();

            dbContext.Accounts.Add(new DBModel.Account {
                UserId = uuid, Email = email, Password = password, State = 1, Type = 0
            });

            if (dbContext.SaveChanges() == 1)
            {
                return(Ok(new
                {
                    status = true,
                    msg = "注册成功"
                }));
            }
            else
            {
                return(Ok(new
                {
                    status = false,
                    msg = "注册失败"
                }));
            }
        }
Ejemplo n.º 6
0
        public ActionResult <string> ModifyInfo(string id, string nickname, int gender, string phoneNumber, string majorID, int year, int degree)
        {
            var info = dbContext.Users.Where(n => n.UserId.Equals(id)).ToList().FirstOrDefault();

            info.NickName    = nickname;
            info.Gender      = gender;
            info.PhoneNumber = phoneNumber;
            info.MajorId     = majorID;
            dbContext.SaveChanges();
            return(Ok(new
            {
                status = true,
                msg = "修改信息成功"
            }));
        }
Ejemplo n.º 7
0
        public ActionResult <IEnumerable <string> > Get()
        {
            #region 新增
            //Province province = new Province
            //{
            //    //int类型的ID默认为主键自增,所以不需要添加。
            //    name="北京",
            //    population=200000
            //};
            //Company company = new Company
            //{
            //    Name = "腾讯",
            //    CreateTime = new DateTime(),
            //    LegalPerson = "小马哥"
            //};
            //_context.AddRange(province, company);
            //_context.SaveChanges();
            #endregion

            #region 查询
            //var province = _context.Provinces.Where(x => x.name == "北京").ToList();
            #endregion

            #region 修改
            var province = _context.Provinces.FirstOrDefault();
            if (province != null)
            {
                province.population += 100;
                _context.Provinces.Add(new Province
                {
                    name       = "上海",
                    population = 200000
                });
                _context.SaveChanges();
            }
            #endregion
            #region  除
            //var province = _context.Provinces.FirstOrDefault();
            //_context.Remove(province);
            //_context.SaveChanges();
            #endregion
            return(new string[] { "value1", "value2" });
        }
Ejemplo n.º 8
0
 //Creating Employing Method *****************************************************
 public void AddEmployeeData(Employee employee)
 {
     employee.TrackingNum = GetRandomNumb();
     _dataDBContext.EmployeeTable.Add(employee);
     _dataDBContext.SaveChanges();
 }