public async Task <Response> CreateTable(GenerateTables model)
        {
            Response res = new Response();

            try
            {
                //var con= RequestFilter.GetContext();
                model.SysUser = _sysUser.ResponseToken(new LoginRequestDTO()
                {
                    Account = "yaogi", Password = "******"
                });
                model.CreateUser = model.SysUser.UserName;
                //model.SysUser = UserCacheHelper.GetSys();
                var data = await context.GenerateTables.Where(m => m.TableName == model.TableName).FirstOrDefaultAsync();

                if (data != null)
                {
                    res.Code    = 0;
                    res.Message = "该表已存在";
                    return(res);
                }


                await context.GenerateTables.AddAsync(model);

                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                res.Code    = 0;
                res.Message = e.Message;
            }
            return(res);
        }
        public async Task <IActionResult> SaveBuilding(BuildingTargetBinding target)
        {
            if (ModelState.IsValid)
            {
                Building building = target.ToBuilding();
                await __context.Buildings.AddAsync(building);

                await __context.SaveChangesAsync();

                return(Ok(building));
            }
            return(BadRequest(ModelState));
        }
        public async Task <Response> SetColumns(GenerateColumns models)
        {
            Response res = new Response();

            try
            {
                var tabledata = await context.GenerateTables.FirstOrDefaultAsync(m => m.Id == models.GenerateTablesId);

                if (tabledata == null)
                {
                    res.Code    = 3;
                    res.Message = "该表存在无法添加字段";
                    return(res);
                }
                var data = context.GenerateColumns.FirstOrDefault(m => m.ColumnName == models.ColumnName);
                if (data != null)
                {
                    res.Code    = 3;
                    res.Message = "该字段已存在";
                    return(res);
                }
                models.GenerateTables = tabledata;
                await context.GenerateColumns.AddAsync(models);

                await context.SaveChangesAsync();

                res.Data = models.Id;
            }
            catch (Exception e)
            {
                res.Code    = 2;
                res.Message = e.Message;
            }
            return(res);
        }
Exemple #4
0
        public async Task <int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            foreach (var entry in _context.ChangeTracker.Entries <AuditableEntity>())
            {
                switch (entry.State)
                {
                case EntityState.Added:
                    entry.Entity.CreatedOn = DateTime.Now;
                    entry.Entity.CreatedBy = _loggedInUserService.UserId ?? "ahejazi";
                    break;

                case EntityState.Modified:
                    entry.Entity.UpdatedOn = DateTime.Now;
                    entry.Entity.UpdatedBy = _loggedInUserService.UserId ?? "ahejazi";
                    break;
                }
            }
            return(await _context.SaveChangesAsync(cancellationToken));
        }
Exemple #5
0
        public async Task <Response> RegisterUser(SysUser model)
        {
            Response res = new Response();

            try
            {
                var data = await context.SysUser.Where(m => m.UserMobile == model.UserMobile && m.IsDel == 0).FirstOrDefaultAsync();

                if (data != null)
                {
                    res.Code    = 3;
                    res.Message = "该手机号码已经被注册";
                    return(res);
                }
                var data1 = await context.SysUser.Where(m => m.UserAccount == model.UserAccount && m.IsDel == 0).FirstOrDefaultAsync();

                if (data1 != null)
                {
                    res.Code    = 3;
                    res.Message = "该用户已存在";
                    return(res);
                }
                model.CreateTime   = DateTime.Now;
                model.UserPassword = ValueConvert.MD5(model.UserPassword);

                await context.SysUser.AddAsync(model);

                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                res.Code    = 2;
                res.Message = e.Message;
            }
            return(res);
        }
 public async Task UpdateAsync(T entity)
 {
     //_dbContext.ChangeTracker.Entries()
     _dbContext.Entry(entity).State = EntityState.Modified;
     await _dbContext.SaveChangesAsync();
 }