public async Task <User> CreateOrUpdateAsync(User input)
        {
            input.CreateTime = DateTime.Now;
            input.Password   = input.Password.GetMd5();

            if (input.Id == 0)
            {
                var ise = await _dbContext.User.FirstOrDefaultAsync(u => u.LoginName == input.LoginName);

                if (ise != null)
                {
                    throw new StringResponseException("用户名已被占用了!");
                }

                var entity = await _dbContext.AddAsync(input);

                await _dbContext.SaveChangesAsync();

                return(entity.Entity);
            }

            if (input.LoginName == "admin")
            {
                throw new StringResponseException("这个可不能改哦!");
            }

            _dbContext.Update(input);
            await _dbContext.SaveChangesAsync();

            return(input);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Customer> > CreateAsync([FromBody] CreateCustomerCommand customer)
        {
            var entity = customer.Build();

            await _defaultDbContext.AddAsync(entity);

            await _defaultDbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetById), new { id = entity.Id }, entity));
        }
Ejemplo n.º 3
0
        public async Task <Course> CreateOrUpdateAsync(Course input)
        {
            if (input.Id == 0)
            {
                var entity = await _dbContext.AddAsync(input);

                await _dbContext.SaveChangesAsync();

                return(entity.Entity);
            }

            _dbContext.Update(input);
            await _dbContext.SaveChangesAsync();

            return(input);
        }
        public async Task <Honor> CreateOrUpdateAsync(Honor input)
        {
            input.CreateTime = DateTime.Now;

            if (input.Id == 0)
            {
                var entity = await _dbContext.AddAsync(input);

                await _dbContext.SaveChangesAsync();

                return(entity.Entity);
            }

            _dbContext.Update(input);
            await _dbContext.SaveChangesAsync();

            return(input);
        }
Ejemplo n.º 5
0
        public async Task <DataDictionary> CreateOrUpdateAsync(DataDictionary input)
        {
            if (input.Id == 0)
            {
                var ex = await _dbContext.DataDictionary.AnyAsync(d => !d.IsDeleted && d.Key == input.Key);

                if (ex)
                {
                    throw new StringResponseException("key 已存在!");
                }

                var entity = await _dbContext.AddAsync(input);

                await _dbContext.SaveChangesAsync();

                return(entity.Entity);
            }

            _dbContext.Update(input);
            await _dbContext.SaveChangesAsync();

            return(input);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 用户登录记录事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public void UserLogin_Login_Handler(object sender, UserDto e)
 {
     //事务
     try
     {
         Task.Run(async() =>
         {
             using (var db = new DefaultDbContext(_config.ConnType, _config.ConnName))
             {
                 using (var transaction = db.Database.BeginTransaction())
                 {
                     var entity = _mapper.Map <UserLogin>(e.userLoginDto);
                     await db.AddAsync(entity);
                     await db.SaveChangesAsync();
                     await transaction.CommitAsync();
                 }
             }
         });
     }
     catch (Exception ex)
     {
         //TODO 记录错误日志
     }
 }