Пример #1
0
        public async Task <ActionResult> SetContent([FromRoute] int id, [FromBody] byte[] content)
        {
            var post = await _context.BlogPosts.FindAsync(id);

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

            post.Content = content;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogPostExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        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);
        }
Пример #3
0
        public async Task <IActionResult> AddStudent([FromBody] Student model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                _context.Students.Add(model);
                await _context.SaveChangesAsync();

                var data = new { error = 0, message = "Successfully created", obj = model };
                return(new JsonResult(data)
                {
                    StatusCode = StatusCodes.Status200OK
                });
            }
            catch (Exception ex)
            {
                var data = new { error = 1, message = ex.Message, trace = ex.StackTrace.ToString() };
                return(new JsonResult(data)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Пример #4
0
        public async Task <T> Create(T entity)
        {
            EntitySet.Add(entity);
            await DbContext.SaveChangesAsync();

            return(entity);
        }
Пример #5
0
        public async Task <IActionResult> CreatePrivateRoom(Guid?userId)
        {
            var user = this._context.Users.Include(x => x.Shops).FirstOrDefault(x => x.Id == userId);
            var chat = new Chat
            {
                Id   = Guid.NewGuid(),
                Name = "My Private Chat With" + " " + user.Shops.BusinessName,
                Type = Infrastructures.Domain.Enums.ChatType.Private
            };

            chat.Users.Add(new ChatUser
            {
                UserId = userId
            });

            chat.Users.Add(new ChatUser
            {
                UserId = WebIDS.UserId
            });

            this._context.Chats.Add(chat);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Chat", new { ChatId = chat.Id }));
        }
        public async Task <IActionResult> PutBlogUser(int id, BlogUser blogUser)
        {
            if (id != blogUser.Id)
            {
                return(BadRequest());
            }

            _context.Entry(blogUser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #7
0
        public async Task <IActionResult> UpdateAsync([FromBody] RegisterModel model)
        {
            if (model == null)
            {
                return(BadRequest("Invalid model"));
            }

            var user = await _dbContext.Users
                       .Where(a => a.Email.Equals(model.Email))
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                return(NotFound("Cannot find an user with this e-mail."));
            }

            user.Name     = model.Name;
            user.Password = model.Password;

            await _dbContext.SaveChangesAsync();

            user.Password = null;

            return(Ok(user));
        }
Пример #8
0
        async Task INotificationHandler <TeamAssignmentCreated> .Handle(TeamAssignmentCreated e, CancellationToken t)
        {
            var team =
                await db.Teams
                .SingleOrDefaultAsync(m => m.InternalId == e.TeamId);

            var member =
                await db.Members
                .SingleOrDefaultAsync(m => m.InternalId == e.MemberId);

            var model =
                await db.TeamAssignments.AddAsync(
                    new TeamAssignmentData
            {
                Member = new TeamAssignmentData.MemberData
                {
                    CompleteName = member.CompleteName,
                    SortableName = member.SortableName,
                    MemberNumber = member.MemberNumber,
                    MemberId     = member.InternalId,
                },
                Team = new TeamAssignmentData.TeamData
                {
                    CommonName       = team.CommonName,
                    UniqueIdentifier = team.UniqueIdentifier,
                    TeamId           = team.InternalId,
                },
                IsCanceled = false,
                InternalId = e.Id
            });

            await db.SaveChangesAsync(t);
        }
        public async Task <EventlogHospitalGoods> Handle(IReceiveContext <CreateEventlogHospitalGoodsRequest> context, CancellationToken cancellationToken)
        {
            var created = context.Message;
            var log     = new Eventlog
            {
                Content      = "-",
                Title        = $"修改药品 {created.HospitalGoods.Name}",
                OptionUserId = created.UserId,
                CreateTime   = DateTime.Now,
            };

            _context.Eventlog.Add(log);
            await _context.SaveChangesAsync();

            var reference = new EventlogHospitalGoods
            {
                HospitalGoodsId = created.GoodsId,
                EventlogId      = log.Id,
            };

            _context.EventlogHospitalGoods.Add(reference);

            await _context.SaveChangesAsync();

            return(reference);
        }
        public async Task DeleteAllByClientIdAsync(int clientId)
        {
            var data = _context.Client2HospitalClient.Where(x => x.ClientId == clientId);

            _context.Client2HospitalClient.RemoveRange(data);
            await _context.SaveChangesAsync();
        }
Пример #11
0
        public async Task CreateEmployeeAsync(Employee employee)
        {
            var employeeDb = EmployeeMapper.Map(employee);

            await defaultDbContext.EmployeeDbs.AddAsync(employeeDb).ConfigureAwait(false);

            await defaultDbContext.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #12
0
        public async Task <Client> CreateAsync(Client payload)
        {
            payload.CreateTime = DateTime.Now;
            _context.Client.Add(payload);
            await _context.SaveChangesAsync();

            return(payload);
        }
        public async Task InActiveVerificationCodeListAsync(string phone)
        {
            var verifications = _context.UserVerificationCode.Where(x => x.IsActive == 1 && x.Phone == phone).ToList();

            foreach (var verification in verifications)
            {
                verification.IsActive = 0;
            }
            await _context.SaveChangesAsync();
        }
Пример #14
0
        async Task INotificationHandler <IncentivePaid> .Handle(IncentivePaid e, CancellationToken cancellationToken)
        {
            var incentive =
                await db.Incentives
                .SingleAsync(t => t.InternalId == e.Id);

            incentive.IsPaid = true;
            incentive.PaidAt = e.TimeStamp;

            await db.SaveChangesAsync();
        }
Пример #15
0
        public async Task <IActionResult> Create([Bind("Id,Title,IsDone")] ToDo toDo)
        {
            if (ModelState.IsValid)
            {
                toDo.UserId = _userManager.GetUserId(HttpContext.User);
                _context.Add(toDo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDo));
        }
Пример #16
0
        public async Task <IActionResult> Post([FromBody] Group model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Groups.Add(model);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Пример #17
0
        public async Task <IActionResult> Post([FromBody] Contact model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Contacts.Add(model);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetContact", new { id = model.Id }, model));
        }
Пример #18
0
        async Task INotificationHandler <LedgerAccountCreated> .Handle(LedgerAccountCreated e, CancellationToken t)
        {
            var model =
                await db.LedgerAccounts.AddAsync(
                    new LedgerAccountData
            {
                CommonName              = e.CommonName,
                AccountNumber           = e.AccountNumber,
                LedgerAccountExternalId = e.Id,
            });

            await db.SaveChangesAsync(t);
        }
Пример #19
0
        async Task INotificationHandler <CostCodeCreated> .Handle(CostCodeCreated e, CancellationToken t)
        {
            var model =
                await db.CostCodes.AddAsync(
                    new CostCodeData
            {
                CommonName         = e.CommonName,
                UniqueIdentifier   = e.UniqueIdentifier,
                CostCodeExternalId = e.Id,
            });

            await db.SaveChangesAsync(t);
        }
        async Task INotificationHandler <IncentiveTypeCreated> .Handle(IncentiveTypeCreated e, CancellationToken cancellationToken)
        {
            var incentiveType =
                await db.IncentiveTypes.AddAsync(
                    new IncentiveTypeData
            {
                InternalId = e.Id,
                CommonName = e.CommonName,
                IsActive   = true,
            });

            await db.SaveChangesAsync(cancellationToken);
        }
Пример #21
0
        async Task INotificationHandler <TeamCreated> .Handle(TeamCreated e, CancellationToken t)
        {
            var model =
                await db.Teams.AddAsync(
                    new TeamData
            {
                CommonName       = e.CommonName,
                UniqueIdentifier = e.UniqueIdentifier,
                InternalId       = e.Id,
            });

            await db.SaveChangesAsync(t);
        }
Пример #22
0
        public async Task <IActionResult> Post([FromBody] AddEmployeeDto item)
        {
            try
            {
                if (item == null)
                {
                    return(BadRequest());
                }

                var contact = new Contact()
                {
                    FirstName       = item.FirstName,
                    LastName        = item.LastName,
                    Phone           = item.Phone,
                    MobilePhone     = item.MobilePhone,
                    Email           = item.Email,
                    OfficialEmail   = item.OfficialEmail,
                    PhysicalStreet  = item.Street,
                    PhysicalState   = item.State,
                    PhysicalCity    = item.City,
                    PhysicalZipCode = item.ZipCode,
                    PhysicalCountry = item.Country
                };

                var emp = new Employee()
                {
                    ContactId        = contact.Id,
                    EmployeeTypeId   = item.EmployeeTypeId,
                    DesignationId    = item.DesignationId,
                    IsUnderProbation = item.IsUnderProbation,
                    EmployeeStatusId = item.EmployeeStatusId,
                    HiredAt          = DateTime.Now,
                    ABAAccountName   = item.ABAAccountName,
                    ABAAccountNumber = item.ABAAccountName,
                    Remarks          = item.Remarks
                };

                _context.Contacts.Add(contact);
                emp.Contact = contact;
                _context.Employees.Add(emp);
                await _context.SaveChangesAsync();

                return(Ok(emp.Id));
            }
            catch (Exception e)
            {
                _logger.LogError("API_ERR | POST_EMPLOYEE | item: {0} | ERR: {1}", JsonConvert.SerializeObject(item), e.StackTrace.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Пример #23
0
        public async Task <IActionResult> Post([FromBody] UserSettings model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            model.Updated = DateTime.UtcNow;
            model.UserId  = CurrentUserId;

            _context.UserSettings.Add(model);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetSettings", new { id = model.Id }, model));
        }
Пример #24
0
        /// <summary>
        ///  插入单个实体
        /// </summary>
        /// <param name="entity">要插入的实体</param>
        /// <returns>返回受影响行数</returns>
        public virtual async Task <int> InsertAsync(T entity)
        {
            SetCreateBy(entity);

            await dbSet.AddAsync(entity);

            return(await DbContext.SaveChangesAsync());
        }
Пример #25
0
        async Task INotificationHandler <MemberTypeCreated> .Handle(MemberTypeCreated e, CancellationToken c)
        {
            var memberType =
                await db.MemberTypes
                .AddAsync(
                    new MemberTypeData
            {
                CommonName  = e.CommonName,
                IsActive    = true,
                MemberCount = 0,
                InternalId  = e.Id,
            });

            await db.SaveChangesAsync(c);
        }
Пример #26
0
        public async Task Handle(IReceiveContext <DeleteClient2HospitalClientCommand> context, CancellationToken cancellationToken)
        {
            var mapping = _context.Client2HospitalClient.Find(context.Message.Id);

            _context.Client2HospitalClient.Remove(mapping);
            await _context.SaveChangesAsync();
        }
Пример #27
0
 /// <summary>
 /// 用户登录成功加分事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void UserAccount_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       = await db.UserAccount.AsQueryable().FirstOrDefaultAsync(m => m.UserID == e.Id);
                     entity.Integral += e.userAccountDto.Integral;
                     db.UserAccount.Update(entity);
                     await db.SaveChangesAsync();
                     await transaction.CommitAsync();
                 }
             }
         });
     }
     catch (Exception ex)
     {
         //TODO 记录错误日志
     }
 }
Пример #28
0
        public async Task Send(string message, Guid?userid, Guid?chatid, string username)
        {
            var otheruser = this._context.Chats
                            .Include(x => x.Users)
                            .FirstOrDefault(u => u.Id == chatid && u.Type == Infrastructures.Domain.Enums.ChatType.Private);

            var otherusers = this._context.ChatUsers.FirstOrDefault(cu => cu.UserId != WebIDS.UserId && cu.ChatId == chatid);

            var Message = new Message()
            {
                Id        = Guid.NewGuid(),
                Text      = message,
                ChatId    = chatid,
                UserId    = userid,
                Name      = username,
                CreatedAt = DateTime.UtcNow,
                UpdatedAt = DateTime.UtcNow,
                Timestamp = DateTime.UtcNow,
            };

            this._context.Messages.Add(Message);
            await _context.SaveChangesAsync();

            await Clients.All.SendAsync("SendMessage", username, message, Message.Timestamp.ToString("hh:mm tt"), Message.Timestamp.ToString("MMMM dd"), userid, otherusers.UserId);
        }
Пример #29
0
        public async Task <IActionResult> RegisterAsync([FromBody] RegisterModel model)
        {
            if (model == null)
            {
                return(BadRequest("Invalid model"));
            }

            if (await _dbContext.Users.AnyAsync(a => a.Email.Equals(model.Email)))
            {
                return(UnprocessableEntity("Already exists an user with this e-mail."));
            }

            var user = new User
            {
                Name     = model.Name,
                Email    = model.Email,
                Password = model.Password,
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.SaveChangesAsync();

            user.Password = null;

            return(Created($"{HttpContext.Request.Host}users/{user.Id}", user));
        }
Пример #30
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);
        }