public static void SetCurrentPack(string packName) { CurrentPack = Packs.FirstOrDefault(p => p.Name == packName); if (CurrentPack == null) { CurrentPack = Packs.First(); } }
public static void DeletePack(SmileyPack pack) { if (pack.IsDefault) { throw new ArgumentException("Cannot delete a default pack."); } Packs.Remove(pack); Directory.Delete(GetPath(pack), true); CurrentPack = Packs.First(); }
//public IList<GoodsReview> GoodsReviews { get; set; } public decimal PriceForPack(int packId) { var pack = Packs.First(x => x.PackInfo.PackId == packId); //Если базовая упаковка или меньше базовой - не применяем скидку bool noPackDiscount = pack.PackInfo.PackId == BasePackId || pack.PackInfo.Size <= BasePack.Size; decimal price = pack.Price ?? (noPackDiscount ? Price * (decimal)pack.PackInfo.Size / (decimal)BasePack.Size : Price * (decimal)pack.PackInfo.Size / (decimal)BasePack.Size * (100m - (decimal)(pack.Discount ?? pack.PackInfo.DefaultDiscount ?? 0)) / 100m); return(Math.Round(price, 0, MidpointRounding.AwayFromZero)); }
public static void Load() { string currentPackName = CurrentPack == null ? null : CurrentPack.Name; Packs.Clear(); var defaultDirs = new DirectoryInfo(DefaultSmileysFolder).EnumerateDirectories(); var customDirs = new DirectoryInfo(CustomSmileysFolder).EnumerateDirectories(); foreach (var dir in defaultDirs.Concat(customDirs)) { var doc = XDocument.Load(Path.Combine(dir.FullName, ManifestFileName)); bool isDefault = bool.Parse(doc.Root.Attribute(IsDefaultAttributeName).Value); var pack = new SmileyPack(dir.Name, isDefault); foreach (var elem in doc.Root.Elements(SmileyElementName)) { string fileName = elem.Attribute(FileNameAttributeName).Value; string[] shortcuts = elem.Attribute(ShortcutsAttributeName).Value .Split(SmileyShortcutsSeparator); var smiley = new Smiley(); smiley.FileName = fileName; smiley.Image = GetImage(Path.Combine(GetPath(pack), fileName)); foreach (string s in shortcuts) { smiley.Shortcuts.Add(s); } pack.Smileys.Add(smiley); } Packs.Add(pack); } if (currentPackName == null) { CurrentPack = Packs.First(); } else { SetCurrentPack(currentPackName); } }