//[HttpPost]
        //public ActionResult Add()
        //{

        //}

        private int AddData()
        {
            var xx = sqlContext.Products.ToList();

            sqlContext.Products.RemoveRange(xx);
            sqlContext.SaveChanges();
            List <Product> products = new List <Product>();

            for (var i = 1; i <= 3; i++)
            {
                products.Add(new Product()
                {
                    Id          = i,
                    Description = "商品" + i,
                    Price       = i * 100,
                    Genre       = "all",
                    Title       = "标题" + i,
                    ReleaseDate = DateTime.Today,
                    Photo       = @"../Upload/ShopImage/" + i + ".png",
                });
            }

            sqlContext.Products.AddRange(products);
            return(sqlContext.SaveChanges());
        }
示例#2
0
        public IHttpActionResult FollowSubject([FromUri] string AccessToken, [FromUri] int SubjectId)
        {
            var UserId  = TokenValidator.VerifyToken(AccessToken);
            var Subject = SQLContext.Subjects.Find(SubjectId);

            if (Subject == null)
            {
                return(NotFound());
            }

            var AlreadyExists = UserAuxiliar.FollowedSubjects(UserId, SQLContext).Contains(Subject);

            if (AlreadyExists)
            {
                return(Ok("Already Exists"));
            }

            var UserInterest = new UserSubject()
            {
                UserId    = UserId,
                SubjectId = SubjectId
            };

            SQLContext.UserSubjects.Add(UserInterest);
            SQLContext.SaveChanges();

            return(Ok(UserInterest));
        }
示例#3
0
        public IHttpActionResult CreateFollow([FromUri] string AccessToken, [FromUri] int RequestedUserId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var UserId = TokenValidator.VerifyToken(AccessToken);

            var AlreadyExists = SQLContext.Follows
                                .Where(x => x.FollowedId == RequestedUserId && x.FollowerId == UserId)
                                .Any();

            if (AlreadyExists)
            {
                return(Ok("Already Exists"));
            }

            var Follow = new Follow()
            {
                FollowerId = UserId,
                FollowedId = RequestedUserId
            };

            SQLContext.Follows.Add(Follow);
            SQLContext.SaveChanges();

            return(Ok(Follow));
        }
示例#4
0
        public IHttpActionResult UpdateUser([FromUri] int UserId, [FromBody] User User)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (UserId != User.Id)
            {
                return(BadRequest());
            }

            SQLContext.Entry(User).State = EntityState.Modified;

            try
            {
                SQLContext.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(UserId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#5
0
        public IHttpActionResult CreateProduct([FromUri] string AccessToken, [FromBody] Product Product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var UserId = TokenValidator.VerifyToken(AccessToken);
            var User   = SQLContext.Users.Find(UserId);

            if (User == null || !User.IsPro)
            {
                return(NotFound());
            }

            if (Product.Name.Contains(" "))
            {
                Product.Name = Product.Name.Replace(' ', '_');
            }

            Product.ProId = UserId;

            SQLContext.Products.Add(Product);
            SQLContext.SaveChanges();

            return(Ok(Product));
        }
示例#6
0
        private Media TreatMediaCreation(string Name, string FileExtension, int UserId, bool IsUserMedia)
        {
            var MediaType = SQLContext.TypeMedias.Where(x => x.Name == FileExtension).FirstOrDefault();

            if (MediaType == default)
            {
                MediaType = new TypeMedia {
                    Name = FileExtension
                };

                SQLContext.TypeMedias.Add(MediaType);
                SQLContext.SaveChanges();
            }

            var NewMedia = new Media {
                URL = Url.Content(Path.Combine("~/Media_Data", Name))
            };

            SQLContext.Medias.Add(NewMedia);
            SQLContext.SaveChanges();

            if (IsUserMedia)
            {
                var User = SQLContext.Users.Find(UserId);
                User.MediaId = NewMedia.Id;
                SQLContext.Entry(User).State = System.Data.Entity.EntityState.Modified;
            }

            SQLContext.SaveChanges();

            return(NewMedia);
        }
        public bool RevokeToken(string userName)
        {
            var user = _context.Users.SingleOrDefault(u => u.UserName == userName);

            if (user is null)
            {
                return(false);
            }
            user.RefreshToken = null;
            _context.SaveChanges();
            return(true);
        }
示例#8
0
        public IHttpActionResult CreateSubject([FromBody] Subject Subject)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            SQLContext.Subjects.Add(Subject);
            SQLContext.SaveChanges();

            return(Ok(Subject));
        }
示例#9
0
        public ActionResult Edit(grade grade)
        {
            if (ModelState.IsValid)
            {
                var      crs     = DB.courses.FirstOrDefault(s => s.ID.Equals(grade.CourseID));
                DateTime datenow = DateTime.Now;
                DateTime ExamA   = crs.ExamA;
                DateTime ExamB   = crs.ExamB;

                int valueA = DateTime.Compare(ExamA, datenow);
                int valueB = DateTime.Compare(ExamB, datenow);

                // checking

                /* if (valueA < 0)
                 * {
                 *   ModelState.AddModelError("GradeA", "you can update the grade of moed A after the date of the exam");
                 * }
                 * if (valueB < 0)
                 * {
                 *   ModelState.AddModelError("GradeB", "you can update the grade of moed B after the date of the exam");
                 * }*/
                if (valueA < 0 || grade.GradeA == null)
                {
                    if (valueB < 0 || grade.GradeB == null)
                    {
                        try
                        {
                            var grad = DB.grades.FirstOrDefault(s => s.CourseID.Equals(grade.CourseID) && s.StudentID.Equals(grade.StudentID));
                            grad.CourseID  = grade.CourseID;
                            grad.GradeA    = grade.GradeA;
                            grad.GradeB    = grade.GradeB;
                            grad.StudentID = grade.StudentID;
                            DB.SaveChanges();
                            return(RedirectToAction("show"));
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("GradeB", "you can update the grade of moed B after the date of the exam");
                    }
                }
                else
                {
                    ModelState.AddModelError("GradeA", "you can update the grade of moed A after the date of the exam");
                }
            }
            return(View(grade));
        }
示例#10
0
        public virtual void Add(TEntity obj)
        {
            try
            {
                _context.Set <TEntity>().Add(obj);
                _context.SaveChanges();
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
 //Cria nova pessoa
 public Person Create(Person person)
 {
     try
     {
         _context.Add(person);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(person);
 }
示例#12
0
 public T Create(T item)
 {
     try
     {
         _dataSet.Add(item);
         _context.SaveChanges();
         return(item);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#13
0
 public Produto Criar(Produto produto)
 {
     try
     {
         _context.Add(produto);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(produto);
 }
示例#14
0
 public EstadoCivil Create(EstadoCivil estadoCivil)
 {
     try
     {
         _context.Add(estadoCivil);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(estadoCivil);
 }
示例#15
0
        public ActionResult AddMenuToDb(string menuData)
        {
            MenuObject data = Newtonsoft.Json.JsonConvert.DeserializeObject <MenuObject>(menuData);

            using (SQLContext context = GetSQLContext())
            {
                Menu menu = new Menu
                {
                    ID          = data.ID == new Guid() ? Guid.NewGuid() : data.ID,
                    Cost        = data.Cost,
                    Name        = data.Name,
                    Meals       = context.Meals.Where(x => x.Name == data.MainCourse || x.Name == data.Dessert || x.Name == data.Appetizer).ToList(),
                    Drinks      = context.Drinks.Where(x => x.Name == data.Drink).ToList(),
                    Description = data.Description
                };

                if (context.Menus.FirstOrDefault(x => x.ID == data.ID) != null)
                {
                    context.Menus.FirstOrDefault(x => x.ID == data.ID).Meals.Clear();
                    context.Menus.FirstOrDefault(x => x.ID == data.ID).Drinks.Clear();
                    context.Menus.Remove(context.Menus.FirstOrDefault(x => x.ID == data.ID));
                }

                context.Menus.Add(menu);
                context.SaveChanges();
            }


            return(RedirectToAction("MenuView"));
        }
示例#16
0
        public IActionResult EditBloger(Bloger bloger, IFormFile file)
        {
            string filehead = DateTime.Now.ToString("yyyyMMddHHmmss");


            if (file != null)
            {
                bloger.Backpic = UpFile(file);
                bloger.Mid     = 1;
                bloger.Status  = 0;
                bloger.AddTime = bloger.UpdateTime = DateTime.Now;
                using (SQLContext DB = new SQLContext())
                {
                    try
                    {
                        DB.Bloger.Add(bloger);
                        DB.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.Message);
                        throw ex;
                    }
                    return(RedirectToAction("Index"));
                };
            }
            return(View(bloger));
        }
示例#17
0
 public void Insert(T obj)
 {
     using (var data = new SQLContext(_OptionsBuilder))
     {
         data.Set <T>().Add(obj);
         data.SaveChanges();
     }
 }
示例#18
0
 public void Delete(int id)
 {
     using (var data = new SQLContext(_OptionsBuilder))
     {
         data.Set <T>().Remove(Select(id));
         data.SaveChanges();
     }
 }
示例#19
0
        public void CancelarMatriculaI(int codigoMatricula)
        {
            var teste = context.Matricula.Where(a => a.CodigoMatricula == codigoMatricula).ToList();
            var mat   = context.Matricula.Where(a => a.CodigoMatricula == codigoMatricula).FirstOrDefault();

            mat.CodigoSituacao = (int)SituacaoMatricula.Inativa;
            context.SaveChanges();
        }
示例#20
0
 public void Update(T obj)
 {
     using (var data = new SQLContext(_OptionsBuilder))
     {
         data.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         data.SaveChanges();
     }
 }
示例#21
0
        public ActionResult RemoveDrink(Guid id)
        {
            using (SQLContext context = GetSQLContext())
            {
                context.Drinks.FirstOrDefault(x => x.ID == id).Menus.Clear();
                context.Drinks.Remove(context.Drinks.FirstOrDefault(x => x.ID == id));
                context.SaveChanges();
            }

            return(RedirectToAction("DrinkView"));
        }
示例#22
0
        public ActionResult AddMealToDb(Meal meal)
        {
            using (SQLContext context = GetSQLContext())
            {
                meal.ID = meal.ID == new Guid() ? Guid.NewGuid() : meal.ID;
                context.Meals.AddOrUpdate(meal);
                context.SaveChanges();
            }

            return(RedirectToAction("MealView"));
        }
示例#23
0
        public ActionResult AddDrinkToDb(Drink drink)
        {
            using (SQLContext context = GetSQLContext())
            {
                drink.ID = drink.ID == new Guid() ? Guid.NewGuid() : drink.ID;
                context.Drinks.AddOrUpdate(drink);
                context.SaveChanges();
            }

            return(RedirectToAction("DrinkView"));
        }
示例#24
0
        public ActionResult Index(User user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }
            db.Users.Add(user);
            db.SaveChanges();

            return(Redirect("/Register/Reminder"));
        }
 public ActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = new AppUser {
             UserName = model.UserName, PassWord = model.PassWord, Email = model.Email
         };
         allData.Users.Add(user);
         int code = allData.SaveChanges();
         if (code > 0)
         {
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             return(Content("注册保存失败"));
         }
     }
     else
     {
         return(Content("注册信息填写有误导致失败"));
     }
 }
        public JsonResult Save(SeatSourceViewModel model)
        {
            JsonResult result = new JsonResult();

            sqlContext.Database.CreateIfNotExists();

            SeatSource seatSource = new SeatSource();

            seatSource.SeatNo          = model.SeatNo;
            seatSource.Number          = model.Number;
            seatSource.Date            = model.Date;
            seatSource.Belongs         = model.Belongs;
            seatSource.ComputerSources = model.ComputerSources;

            sqlContext.SeatSources.Add(seatSource);
            int code = sqlContext.SaveChanges();

            result.Data = code;
            return(Json(result));
        }
示例#27
0
        public async Task <JexusSql> CreateJexusSh(List <string> shList, SQLContext context, JexusSql jexusSql)
        {
            string dirPath = shDir + @"/" + DateTime.Now.Date.ToString("yyyyMMdd");

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            string filename = DateTime.Now.ToString("yyyyMMddHHmmssff");
            var    filepath = dirPath + @"/" + filename + ".sh";

            //在硬盘中写入文件、在数据库中生成数据
            await Task.Run(() =>
            {
                FileStream fileStream     = new FileStream(filepath, FileMode.Create);
                StreamWriter streamWriter = new StreamWriter(fileStream);
                //写入命令到 sh
                streamWriter.WriteLine("cd /usr/jexus/siteconf");
                streamWriter.WriteLine("echo >" + jexusSql.Sitename);
                foreach (var i in shList)
                {
                    streamWriter.WriteLine(@"echo " + "\"" + i + "\"");
                }

                streamWriter.WriteLine("cd /usr/jexus");
                streamWriter.WriteLine("./jws strat " + jexusSql.Sitename);
                //写入结束
                streamWriter.Close();
                fileStream.Close();
                //写入数据库
                jexusSql.DateTime = DateTime.Now;
                jexusSql.FilePath = filepath;
                jexusSql.DownM    = filename;
                context.jexusSqls.Add(jexusSql);
                context.SaveChanges();
            });

            return(jexusSql);
        }
示例#28
0
        private List <int> CheckHashtagsExistence(List <string> Hashtags, Post NewPost)
        {
            List <int> Subjects = new List <int>();

            foreach (var Hashtag in Hashtags)
            {
                var Exists = SQLContext.Subjects.FirstOrDefault(x => x.Hashtag == Hashtag);

                if (Exists == default)
                {
                    var NewSubject = new Subject()
                    {
                        Hashtag = Hashtag
                    };

                    if (NewPost.Medias != null)
                    {
                        if (NewPost.Medias.Count > 0)
                        {
                            NewSubject.MediaId = NewPost.Medias[0];
                        }
                    }

                    var Added = SQLContext.Subjects.Add(NewSubject);
                    SQLContext.SaveChanges();

                    Subjects.Add(Added.Id);
                }

                else
                {
                    Subjects.Add(Exists.Id);
                }
            }

            return(Subjects);
        }
        public Usuario AtualizarInformacoesUsuario(Usuario usuario)
        {
            if (!Existe(usuario.Id))
            {
                return(null);
            }

            var result = _context.Produtos.SingleOrDefault(p => p.Id.Equals(usuario.Id));

            if (result != null)
            {
                try
                {
                    _context.Entry(result).CurrentValues.SetValues(usuario);
                    _context.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(usuario);
        }
示例#30
0
        public void SeedUsers()
        {
            var userData = System.IO.File.ReadAllText("../APP.Data/Seed/SeedBaseUsers.json");
            var users    = JsonConvert.DeserializeObject <List <User> >(userData);

            users = users.Where(x => !_users.Select(y => y.Email).Contains(x.Email)).ToList();


            foreach (var user in users)
            {
                byte[] passwordHash, passwordSalt;
                CreatePasswordHash("admin", out passwordHash, out passwordSalt);

                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;
                user.Username     = user.Username.ToLower();
                user.Email        = user.Email.ToLower();
                user.Created      = DateTime.Now;

                _users.Add(user);
            }

            _context.SaveChanges();
        }