public bool AddAwardToUser(User user, Award award) { if (dalJson.awardedList.Where(item => item[0] == user.id && item[1] == award.id).Count() > 0) { return(false); } Data data = dalJson.LoadAll(); if (data != null) { Guid[] pair = new Guid[] { user.id, award.id }; data.awardedUsers.Add(pair); dalJson.awardedList.Add(pair); if (dalJson.SaveAll(data)) { return(true); } dalJson.awardedList.Remove(pair); } return(false); }
public bool AddUser(User user) { Data data = dalJson.LoadAll(); if (data != null && dalJson.userList.Where(item => item.Value.name == user.name && item.Value.age == user.age && item.Value.birth == user.birth).Count() == 0) { data.userList.Add(user); if (dalJson.SaveAll(data)) { dalJson.userList.Add(user.id, user); return(true); } } return(false); }
public bool AddAward(Award award) { Data data = dalJson.LoadAll(); if (data != null && dalJson.awardList.Where(item => item.Value.title == award.title).Count() == 0) { data.awardList.Add(award); if (dalJson.SaveAll(data)) { dalJson.awardList.Add(award.id, award); return(true); } } return(false); }
public string CreateEmblem(IHaveID item, string ext, BinaryReader br) { Guid emblemId = Guid.NewGuid(); string savePath = $"{path}\\images\\avatars\\"; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } try { using (br) { int lenght = (int)br.BaseStream.Length; byte[] file = br.ReadBytes(lenght); File.WriteAllBytes($"{savePath}{emblemId}.{ext}", file); } Data data = dalJson.LoadAll(); if (data.emblemsList.ContainsKey(item.id)) { File.Delete($"{path}{dalJson.emblemsList[item.id].Path.Substring(1)}"); data.emblemsList[item.id].Path = $"./images/avatars/{emblemId}.{ext}"; } else { data.emblemsList.Add(item.id, new Emblem($"./images/avatars/{emblemId}.{ext}")); } if (dalJson.SaveAll(data)) { dalJson.emblemsList = data.emblemsList; return($"./images/avatars/{emblemId}.{ext}"); } return(null); } catch (IOException) { return(null); } }