public DbMessage Save(DbMessage message) { message.Id = Guid.NewGuid().ToString(); message.Timestamp = DateTime.UtcNow.Ticks; using var context = contextFactory.Create(); context.Messages.Add(message); context.SaveChanges(); return(message); }
public string Save(byte[] bytes) { using var context = contextFactory.Create(); var photo = new DbPhoto { Id = Guid.NewGuid().ToString(), Content = bytes, }; context.Photos.Add(photo); context.SaveChanges(); return(photo.Id); }
public DbUser GetOrCreate(string phoneNumber) { using var context = contextFactory.Create(); var existingUser = context.Users.SingleOrDefault(x => x.PhoneNumber == phoneNumber); if (existingUser != null) { if (existingUser.IsRemoved) { existingUser.IsRemoved = false; context.SaveChanges(); } return(existingUser); } var id = Guid.NewGuid().ToString(); var createdUser = new DbUser { Id = id, Nickname = id, PhoneNumber = phoneNumber, Roles = new[] { UserRoleEnum.User }, IsRemoved = false }; context.Users.Add(createdUser); context.SaveChanges(); return(createdUser); }
public DbDialog GetOrCreate(DbDialog dialog) { using var context = contextFactory.Create(); var existingDialog = context.Dialogs.SingleOrDefault(x => x.UserId == dialog.UserId && x.ServiceId == dialog.ServiceId); if (existingDialog == null) { dialog.Id = Guid.NewGuid().ToString(); context.Dialogs.Add(dialog); context.SaveChanges(); } return(dialog); }
public Service Save(Service service) { ValidateTypes(service.Type, service.GetType()); service.Id = Guid.NewGuid().ToString(); service.IsRemoved = false; using var context = contextFactory.Create(); context.Services.Add(ToDbService(service)); context.ServicesMetas.Add(ToDbServiceMeta(service)); context.SaveChanges(); return(service); }