public async Task EditFavorite(string uid, int id, string fchar2) { try { var user = await usermngr.GetUserbyId(uid); if (fchar2 != null && user != null && id > 0) { var exchar = this.GetUsersFavoriteById(uid, id); if (exchar != null) { FavoriteCharacter chr = new FavoriteCharacter(); chr.AddedAt = DateTime.Now; chr.CharacterName = fchar2; chr.uId = exchar.uId; chr.Id = exchar.Id; chr.ServerId = exchar.ServerId; this.db.Entry(exchar).CurrentValues.SetValues(chr); await db.SaveChangesAsync(); } } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } }
protected override void Seed(AZBContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); FavoriteCharacter fav = new FavoriteCharacter(); fav.AddedAt = DateTime.Now; fav.CharacterName = "test"; fav.ServerId = "test"; fav.uId = "test"; context.FavoriteCharacters.AddOrUpdate(fav); GiftHistory gift = new GiftHistory(); gift.ServerId = "test"; gift.uId = "test"; gift.Year = 1; gift.GiftedAt = DateTime.Now; gift.CharacterName = "test"; context.GiftHistory.AddOrUpdate(gift); context.SaveChanges(); }
public FavoriteCharacter GetUsersFavoriteByCharacterName(string uid, string charname) { try { FavoriteCharacter ap = null; if (charname != null && uid != null) { var chars = this.GetUserFavorite(uid); if (chars != null) { foreach (var c in chars) { if (c.CharacterName == charname) { ap = c; break; } } } } return(ap); } catch (Exception ex) { CommonTools.ErrorReporting(ex); return(null); } }
public async void ImportModel(FavoriteCharacter model) { try { if (model != null) { this.AddedAt = model.AddedAt; this.CharacterName = model.CharacterName; this.Id = model.Id; this.ServerId = model.ServerId; this.uId = model.uId; ServerManager mngr = new ServerManager(); var srv = await mngr.getServerbyId(this.ServerId); if (srv != null) { this.ServerName = srv.Name; } } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } }
public FavoriteCharacter ExportModel() { try { FavoriteCharacter ap = new FavoriteCharacter(); ap.AddedAt = this.AddedAt; ap.CharacterName = this.CharacterName; ap.Id = this.Id; ap.ServerId = this.ServerId; ap.uId = this.uId; return(ap); } catch (Exception ex) { CommonTools.ErrorReporting(ex); return(null); } }
public FavoriteCharacter GetUsersFavoriteById(string uid, int id) { try { FavoriteCharacter ap = null; var chars = this.GetUserFavorite(uid); if (chars != null) { ap = chars.Find(x => x.Id == id); } return(ap); } catch (Exception ex) { CommonTools.ErrorReporting(ex); return(null); } }
public async Task AddFavorite(string uid, string fchar, string sid) { try { var user = await usermngr.GetUserbyId(uid); string fchar2 = null; if (fchar.Contains(" ,") == true) { fchar2 = fchar.Replace(" ,", ","); } if (fchar.Contains(", ") == true) { fchar2 = fchar.Replace(", ", ","); } if (fchar.Contains(" , ") == true) { fchar2 = fchar.Replace(" , ", ","); } else { fchar2 = fchar; } if (fchar2 != null && user != null && sid != null) { if (fchar2.Contains(',') == true) { var chars = fchar2.Split(','); if (chars != null) { foreach (var c in chars) { var exchar = await this.ExistFavorite(uid, c, sid); if (exchar == null) { FavoriteCharacter ch = new FavoriteCharacter(); ch.AddedAt = DateTime.Now; ch.ServerId = sid; string name = c.Replace(" ", "_"); ch.CharacterName = c; ch.uId = user.Id; db.FavoriteCharacters.Add(ch); await db.SaveChangesAsync(); } } } } else { var exchar = await this.ExistFavorite(uid, fchar2, sid); if (exchar == null) { FavoriteCharacter ch = new FavoriteCharacter(); ch.AddedAt = DateTime.Now; string name = fchar2.Replace(" ", "_"); ch.CharacterName = fchar2; ch.uId = user.Id; ch.ServerId = sid; db.FavoriteCharacters.Add(ch); await db.SaveChangesAsync(); } } } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } }