public void OnCreatorSave(Client player, string overlay, string blend, string faceFeatures) { using var ctx = new DefaultDbContext(); player.TriggerEvent("OnCreatorStop"); player.TriggerEvent("Freeze", false); AccountModel acc = player.GetData("User"); var characterOverlay = JsonConvert.DeserializeObject <CharacterOverlayModel>(overlay); characterOverlay.CharacterModelId = acc.Character.Id; ctx.CharacterOverlay.Add(characterOverlay); ctx.SaveChanges(); var characterBlend = JsonConvert.DeserializeObject <CharacterBlendModel>(blend); characterBlend.CharacterModelId = acc.Character.Id; ctx.CharacterBlend.Add(characterBlend); ctx.SaveChanges(); var characterFaceFeatures = JsonConvert.DeserializeObject <CharacterFeaturesModel>(faceFeatures); characterFaceFeatures.CharacterModelId = acc.Character.Id; ctx.CharacterFeatures.Add(characterFaceFeatures); ctx.SaveChanges(); acc.Character.Daten = ctx.CharacterOverlay.FirstOrDefault(t => t.CharacterModelId == acc.Character.Id); acc.Character.FaceFeatures = ctx.CharacterFeatures.FirstOrDefault(t => t.CharacterModelId == acc.Character.Id); acc.Character.Blend = ctx.CharacterBlend.FirstOrDefault(t => t.CharacterModelId == acc.Character.Id); acc.Spawn(); }
public bool Update(Role model) { try { //Get item Role with Id from database var item = context.Roles.Where(i => i.Id == model.Id).FirstOrDefault(); //Set value item with value from model item.Id = model.Id; item.Role1 = model.Role1; item.CreatedBy = model.CreatedBy; item.CreatedTime = model.CreatedTime; item.ModifiedBy = model.ModifiedBy; item.ModifiedTime = model.ModifiedTime; item.IsDeleted = model.IsDeleted; item.DeletedBy = model.DeletedBy; item.DeletedTime = model.DeletedTime; item.Status = model.Status; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Teacher model) { try { //Get item user with Id from database var item = context.Teachers.Where(i => i.ID == model.ID).FirstOrDefault(); //Set value item with value from model item.MaGV = model.MaGV; item.SubjectID = model.SubjectID; item.FirstName = model.FirstName; item.LastName = model.LastName; item.Sex = model.Sex; item.Birthday = model.Birthday; item.Address = model.Address; item.Email = model.Email; item.Phone = model.Phone; item.PasswordSalt = PasswordHash.GeneratePasswordSalt(); item.Password = PasswordHash.EncryptionPasswordWithSalt(model.Password, PasswordHash.GeneratePasswordSalt()); item.ModifiedBy = model.ModifiedBy; item.ModifiedTime = DateTime.Now; item.Note = model.Note; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public dynamic EditComponent(int id, int amount) { Component component = db.Components.Where(x => x.Id == id).FirstOrDefault(); component.Amount = amount; db.Entry(component).State = EntityState.Modified; try { db.SaveChanges(); return(new { Success = true, Component = component }); } catch (DbUpdateConcurrencyException) { if (!ComponentExists(id)) { return(NotFound()); } else { return(new { Success = false, Component = component }); } } }
public async Task <User> CreateAsync(UserCreateApiModel created, int userId) { var user = new User { IsActive = 1, Username = created.Username, Phone = created.Phone, CreateUserId = userId, CreateTime = DateTime.Now, }; using (var tran = await _context.Database.BeginTransactionAsync()) { _context.User.Add(user); _context.SaveChanges(); if (created.RoleIds != null && created.RoleIds.Any()) { _context.UserRole.AddRange(created.RoleIds.Select(x => new UserRole { RoleId = x, UserId = user.Id, })); } await _context.SaveChangesAsync(); await tran.CommitAsync(); } return(user); }
/// <summary> /// 索取一个锁行为为 <paramref name="level"/> 的新事务。 /// </summary> /// <param name="level">事务锁定行为。</param> public void RequireNew(IsolationLevel level) { EnsureSession(); if (_transaction != null) { if (_cancelled) { _transaction.Rollback(); _transaction.Dispose(); _transaction = null; } else { _dbContext.SaveChanges(); _transaction.Commit(); } } else { _dbContext.SaveChanges(); } Logger.Debug("创建新的事务,隔离级别 {0}", level); _transaction = _dbContext.Database.BeginTransaction(level); }
public Prescription Create(PrescriptionCreateApiModel created, int departmentId, int userId) { var prescription = new Prescription { HospitalDepartmentId = departmentId, CreateUserId = userId, CreateTime = DateTime.UtcNow, Cardno = created.Cardno, Status = (int)PrescriptionStatus.Pendding, }; _context.Prescription.Add(prescription); _context.SaveChanges(); if (created.HospitalGoods != null && created.HospitalGoods.Any()) { _context.PrescriptionGoods.AddRange(created.HospitalGoods.Select(x => new PrescriptionGoods { HospitalGoodsId = x.Key, PrescriptionId = prescription.Id, Qty = x.Value, })); _context.SaveChanges(); } return(prescription); }
public bool Update(UserRoleRelationship model) { try { //Get item UserRoleRelationship with Id from database var item = context.UserRoleRelationships.Where(i => i.Id == model.Id).FirstOrDefault(); //Set value item with value from model item.Id = model.Id; item.UserId = model.UserId; item.RoleId = model.RoleId; item.CreatedBy = model.CreatedBy; item.CreatedTime = model.CreatedTime; item.ModifiedBy = model.ModifiedBy; item.ModifiedTime = model.ModifiedTime; item.IsDeleted = model.IsDeleted; item.DeletedBy = model.DeletedBy; item.DeletedTime = model.DeletedTime; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public int Generate(int invoiceId, IList <InvoiceReportValueModel> reports) { if (reports.Any()) { foreach (var report in reports) { var d = new InvoiceReport { Amount = report.Amount, InvoiceId = invoiceId, Name = report.Name, }; _context.InvoiceReport.Add(d); _context.SaveChanges(); var records = report.StoreRecordIds.Select(x => new InvoiceReportRecord { InvoiceReportId = d.Id, StoreRecordId = x }); _context.InvoiceReportRecord.AddRange(records); _context.SaveChanges(); } } return(reports.Count); }
public bool Update(Notification model) { try { //Get item user with Id from database var item = context.Notifications.Where(i => i.ID == model.ID).FirstOrDefault(); //Set value item with value from model item.Title = model.Title; item.Content = model.Content; //item.PracticeTypeID = model.PracticeTypeID; item.ModifyBy = model.ModifyBy; item.ModifyTime = DateTime.Now; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Category model) { try { //Get item Category with Id from database var item = context.Categories.Where(i => i.Id == model.Id).FirstOrDefault(); //Set value item with value from model item.CategoryName = model.CategoryName; item.Level = model.Level; item.ParentId = model.ParentId; item.CreatedBy = model.CreatedBy; item.CreatedTime = model.CreatedTime; item.ModifiedBy = model.ModifiedBy; item.ModifiedTime = model.ModifiedTime; item.IsDeleted = model.IsDeleted; item.DeletedBy = model.DeletedBy; item.DeletedTime = model.DeletedTime; item.Status = model.Status; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public SysRole Create(RoleCreateApiModel created, int userId) { var role = new SysRole { Name = created.Name, CreateUserId = userId, CreateTime = DateTime.UtcNow }; using (var tran = _context.Database.BeginTransaction()) { _context.SysRole.Add(role); _context.SaveChanges(); if (created.MenuIds != null && created.MenuIds.Any()) { _context.SysPrivilege.AddRange(created.MenuIds.Select(x => new SysPrivilege { MenuId = x, RoleId = role.Id, })); _context.SaveChanges(); } tran.Commit(); } return(role); }
public bool Create(StudentTeacherRelationship model) { try { //Initialization empty item var item = new StudentTeacherRelationship(); //Set value for item with value from model item.StudentID = model.StudentID; item.TeacherID = model.TeacherID; item.CreateBy = model.CreateBy; item.CreateTime = DateTime.Now; //Add item to entity context.StudentTeacherRelationships.Add(item); //Save to database context.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Customer model) { try { //Get item user with Id from database var item = context.Customers.Where(i => i.Id == model.Id).FirstOrDefault(); //Set value item with value from model item.Username = model.Username; item.Address = model.Address; item.CreatedBy = model.CreatedBy; item.CreatedTime = model.CreatedTime; item.DeletedBy = model.DeletedBy; item.DeletedTime = model.DeletedTime; item.Email = model.Email; item.FirstName = model.FirstName; item.Id = model.Id; item.IsDeleted = model.IsDeleted; item.LastName = model.LastName; item.ModifiedBy = model.ModifiedBy; item.ModifiedTime = model.ModifiedTime; item.PasswordEncrypted = model.PasswordEncrypted; item.PasswordSalt = model.PasswordSalt; item.PhoneNumber = model.PhoneNumber; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Post model) { try { //Get item user with Id from database var item = context.Posts.Where(i => i.Id == model.Id).FirstOrDefault(); //Set value item with value from model item.CategoryId = model.CategoryId; item.Title = model.Title; item.Content = model.Content; item.Summary = model.Summary; item.Resource = model.Resource; item.Image = model.Image; item.Tags = model.Tags; item.CreatedBy = model.CreatedBy; item.CreatedTime = model.CreatedTime; item.IsDeleted = model.IsDeleted; //Save change to database context.SaveChanges(); return(true); } catch { return(false); } }
public virtual int AddNotice(NoticeInputDto noticeInputDto) { var notice = _mapper.Map <EmsTrainNotice>(noticeInputDto); _defaultDbContext.EmsTrainNotices.Add(notice); return(_defaultDbContext.SaveChanges()); }
public virtual int AddSubject(TrainSubjectInputDto trainSubjectInputDto) { var subject = _mapper.Map <EmsTrainSubject>(trainSubjectInputDto); _defaultDbContext.EmsTrainSubjects.Add(subject); return(_defaultDbContext.SaveChanges()); }
public virtual void Delete(int Id) { var blog = _defaultDbContext.Blogs.Include(b => b.Posts).Where(b => b.Id == Id).First(); _defaultDbContext.Blogs.Remove(blog); _defaultDbContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public Topic ChangeStatus(long id) { context.Configuration.ProxyCreationEnabled = false; //Get from database var user = context.Topics .Where(i => i.ID == id) .FirstOrDefault(); user.Status = !user.Status; context.SaveChanges(); return(user); }
public StudentNotificationRelationship ChangeStatus(long id) { context.Configuration.ProxyCreationEnabled = false; //Get from database var user = context.StudentNotificationRelationships .Where(i => i.ID == id) .FirstOrDefault(); user.Status = true; context.SaveChanges(); return(user); }
public ActionResult Create([Bind(Include = "Id,Name,Description,StudentId")] Unit unit) { if (ModelState.IsValid) { db.Units.Add(unit); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "Id", "FirstName", unit.StudentId); return(View(unit)); }
public IActionResult AddCommentWithRating(CommentWithRatingViewModel model) { //for now Hard Code the UserId = 0bb8a75f-68ea-4d27-9c5f-81b8cdd9d000 Guid?userId = Guid.Parse("0bb8a75f-68ea-4d27-9c5f-81b8cdd9d000"); var post = _context.Posts.FirstOrDefault(p => p.Id == model.PostId); if (post != null) { if (post.RatingsEnabled == true) { var userRating = _context.Ratings.FirstOrDefault(r => r.UserId == userId && r.PostId == model.PostId); if (userRating == null) { userRating = new Infrastructure.Domain.Models.Rating() { Score = model.Score, PostId = model.PostId, UserId = userId, IsCounted = true, MaskUser = false }; _context.Ratings.Add(userRating); _context.SaveChanges(); } } if (post.CommentsEnabled == true) { var userComment = new Infrastructure.Domain.Models.Comment() { Content = model.Comment, IsPublished = true, PostId = model.PostId, UserId = userId, MaskUser = false, LikesEnabled = true, Likes = 0, }; _context.Comments.Add(userComment); _context.SaveChanges(); } return(RedirectPermanent("~/posts/" + model.PostId)); } return(NotFound()); }
/// <summary> /// 插入单个实体 /// </summary> /// <param name="entity">要插入的实体</param> /// <returns>返回受影响行数</returns> public virtual int Insert(T entity) { SetCreateBy(entity); dbSet.Add(entity); return(DbContext.SaveChanges()); }
public bool CreateNewScore(Score model) { try { //Initialization empty item var item = new Score(); //Set value for item with value from model item.TopicStudentID = model.TopicStudentID; item.PracticeTypeID = model.PracticeTypeID; item.TeacherScore = model.TeacherScore; item.CreateBy = model.CreateBy; item.CreateTime = DateTime.Now; //Add item to entity context.Scores.Add(item); //Save to database context.SaveChanges(); return(true); } catch { return(false); } }
public virtual int AddTrainPlanQuarter(TrainPlanQuarterInputDto trainPlanQuarterInputDto) { var trainPlanQuarter = _mapper.Map <EmsTrainPlanQuarter>(trainPlanQuarterInputDto); var dept = _defaultDbContext.MbpDepts.Where(d => d.Id == trainPlanQuarterInputDto.DeptId).FirstOrDefault(); if (dept != null) { trainPlanQuarter.DeptName = dept.DeptName; } _defaultDbContext.EmsTrainPlanQuarters.Add(trainPlanQuarter); return(_defaultDbContext.SaveChanges()); }
public IActionResult CommentWithRating(CommentWithRatingViewModel model) { if (!ModelState.IsValid) { return(View()); } var user = this._context.Users.FirstOrDefault(u => u.Id == model.UserId); var service = this._context.Services.FirstOrDefault(s => s.Id == model.ServiceId); if (service != null) { if (service.RatingsEnabled == true) { var userRating = _context.Ratings.FirstOrDefault(r => r.UserId == model.UserId && r.ServiceId == model.ServiceId); if (userRating == null) { userRating = new Infrastructures.Domain.Models.Rating() { Score = model.Score, ServiceId = model.ServiceId, UserId = model.UserId, IsCounted = true, MaskUser = false }; _context.Ratings.Add(userRating); _context.SaveChanges(); } } if (service.CommentsEnabled == true) { var userComment = new Comment() { Content = model.Comment, IsPublished = true, ServiceId = model.ServiceId, UserId = model.UserId, MaskUser = false, LikesEnabled = true, Likes = 0, }; _context.Comments.Add(userComment); _context.SaveChanges(); } return(RedirectPermanent("~/booking/book/" + model.ServiceId)); } return(NotFound()); }
public IActionResult AddCommentWithRating(CommentWithRatingViewModel model) { var user = _context.Users.FirstOrDefault(p => p.Id == model.UserId); var shop = _context.Shops.FirstOrDefault(p => p.Id == model.ShopId); if (shop != null) { if (shop.RatingsEnabled == true) { var userRating = _context.Ratings.FirstOrDefault(s => s.UserId == model.UserId && s.Id == model.ShopId); if (userRating == null) { userRating = new Rating() { Score = model.Score, ShopId = model.ShopId, UserId = model.UserId, IsCounted = true, MaskUser = false, }; _context.Ratings.Add(userRating); _context.SaveChanges(); } if (shop.CommentsEnabled == true) { var userComment = new Comment() { Content = model.Comment, IsPublished = true, ShopId = model.ShopId, UserId = model.UserId, MaskUser = false, LikesEnabled = false, Likes = 0 }; _context.Comments.Add(userComment); _context.SaveChanges(); } //return RedirectPermanent("~/shop/shop-items/" + model.ShopId); return(RedirectPermanent("~/shop/" + model.ShopId)); } } return(NotFound()); }
public StoreInoutGoods Create(StoreInoutGoodsCreateApiModel created, int userId) { var setting = new StoreInoutGoods { StoreInoutId = created.StoreInoutId, HospitalGoodsId = created.HospitalGoodsId, Qty = created.Qty, CreateTime = DateTime.Now, }; _context.StoreInoutGoods.Add(setting); _context.SaveChanges(); return(setting); }
//想想18,也按这种思路改一改先标注newUserExpand.User删除再标注newUserExpand删除 //也可以达到预期 public void Method20() { //准备一条数据 using (var context = new DefaultDbContext()) { var user = new SysUser() { UserName = "******", Password = "******", UserExpand = new SysUserExpand { ExpandValue1 = "user20的补充" } }; context.Entry(user).State = System.Data.Entity.EntityState.Added; context.SaveChanges(); } SysUserExpand newUserExpand = null; using (var context = new DefaultDbContext()) { newUserExpand = context.Set <SysUserExpand>().Include(p => p.User) .SingleOrDefault(o => o.ExpandValue1 == "user20的补充"); } using (var context = new DefaultDbContext()) { context.Entry(newUserExpand.User).State = System.Data.Entity.EntityState.Deleted; context.Entry(newUserExpand).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public static void Setup(DefaultDbContext dbContext) { context = dbContext; SetupRules(); SetupRoles(); SetupMembers(); context.SaveChanges(); }