public async Task <IActionResult> AddPackageItem([FromBody] AddPackageImageInfo info) { var package = await _appDbContext .Packages .FirstOrDefaultAsync(p => p.PackageId == info.PackageId); if (package == null) { return(NotFound()); } var packageImageId = Guid.NewGuid().ToString(); var image = new PackageImage { PackageImageId = packageImageId, PackageId = info.PackageId, Name = info.Name, Description = info.Description, ImageUrl = "" }; await _appDbContext.AddAsync(image); await _appDbContext.SaveChangesAsync(); return(Created(image.PackageImageId, image)); }
protected override BitmapSource Convert(CrewRoleType?roleType, string databaseRootPath) { try { if (roleType == null) { return(null); } string iconKey; switch (roleType.Value) { case CrewRoleType.Commander: iconKey = "commander"; break; case CrewRoleType.Driver: iconKey = "driver"; break; case CrewRoleType.Gunner: iconKey = "gunner"; break; case CrewRoleType.Loader: iconKey = "loader"; break; case CrewRoleType.Radioman: iconKey = "radioman"; break; default: throw new NotSupportedException(); } string type; switch (this.Type) { case CrewRoleIconType.Big: type = "big"; break; case CrewRoleIconType.Small: type = "small"; break; default: throw new NotSupportedException(); } var path = $"gui/maps/icons/tankmen/roles/{type}/{iconKey}.png"; return(PackageImage.Load(databaseRootPath, PackageImage.GuiPackage, path)); } catch (Exception) { return(null); } }
private static JObject ToJObject(PackageImage image) { return(new JObject { { "URL", image.Url }, { "Description", image.Description }, }); }
public ImageSource GetSkillIcon(string icon) { if (icon == null) { return(null); } return(_skillIcons.GetOrCreate(icon, () => PackageImage.Load(_paths.GuiPackageFile, "gui/maps/icons/tankmen/skills/big/" + icon))); }
public ImageSource GetAccessoryIcon(string icon) { if (icon == null) { return(null); } return(_accessoryIcons.GetOrCreate(icon, () => PackageImage.Load(_paths.GuiPackageFile, "gui" + icon.Split(' ').First().Substring(2)))); }
private ImageSource LoadTankIcon(string relativePath, string hyphenKey) { var localPath = string.Format("{0}/{1}.png", relativePath, hyphenKey); if (PackageStream.IsFileExisted(_paths.GuiPackageFile, localPath)) { return(PackageImage.Load(_paths.GuiPackageFile, localPath)); } localPath = string.Format("{0}/noImage.png", relativePath); return(PackageImage.Load(_paths.GuiPackageFile, localPath)); }
public ActionResult Create(CreatePackageViewModel data) { if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid)) { return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" })); } if (ModelState.IsValid) { try { if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0) { TempData["error"] = "Invalid price setting"; return(View("editpackage", data)); } var pack = new Package { depositprice = data.depoprice, details = string.IsNullOrWhiteSpace(data.details) ? null : data.details, name = data.name, price = data.price, studioid = data.studioid, status = "Enabled" }; if (!string.IsNullOrWhiteSpace(data.ImgName)) { PackageImage package = new PackageImage { ImageName = data.ImgName }; pack.PackageImages.Add(package); } db.Packages.Add(pack); db.SaveChanges(); return(RedirectToAction("PackageHome")); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } return(View("editpackage", data)); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string path = null; var propertyName = parameter as string; if (string.IsNullOrEmpty(propertyName)) { path = value as string; } else { if (value.TryGetPropertyValue(propertyName, out object pathObject)) { path = pathObject as string; } } if (string.IsNullOrEmpty(path)) { return(null); } string databaseRootPath = null; var databaseObject = value as IDatabaseObject; if (databaseObject != null) { databaseRootPath = databaseObject.Database.RootPath; } if (string.IsNullOrEmpty(databaseRootPath)) { databaseRootPath = Database.Current.RootPath; } try { return(PackageImage.Load(databaseRootPath, PackageImage.GuiPackage, path)); } catch (Exception) { return(null); } }
protected override BitmapSource Convert(object[] values, string databaseRootPath) { try { if (values == null) { return(null); } var nationKey = (string)values[0]; var rankLevel = (int)values[1]; if (nationKey != "china") { rankLevel = 12 - rankLevel; } string type; switch (this.Type) { case CrewRankIconType.Big: type = "big"; break; case CrewRankIconType.Small: type = "small"; break; default: throw new NotSupportedException(); } var path = $"gui/maps/icons/tankmen/ranks/{type}/{nationKey}-{rankLevel}.png"; return(PackageImage.Load(databaseRootPath, PackageImage.GuiPackage, path)); } catch (Exception) { return(null); } }
internal LocalGameClientPackageImage(LocalGameClientPath paths) { _paths = paths; using (var reader = new BigworldXmlReader(_paths.GetShellListFile(_paths.Nations[0]))) { var element = XElement.Load(reader); _shellIcons = element.Element("icons") .Elements() .ToDictionary(e => e.Name.ToString(), e => PackageImage.Load(_paths.GuiPackageFile, "gui/maps/icons/shell/" + e.Value.Split(' ').First())); } _accessoryIcons = new Dictionary <string, ImageSource>(); _skillIcons = new Dictionary <string, ImageSource>(); _skillSmallIcons = new Dictionary <string, ImageSource>(); _nationSmallIcons = new Dictionary <string, ImageSource>(); _tankSmallIcons = new Dictionary <string, ImageSource>(); _tankBigIcons = new Dictionary <string, ImageSource>(); _tankCountorIcons = new Dictionary <string, ImageSource>(); using (var reader = new BigworldXmlReader(_paths.CommonCrewDataFile)) { var element = XElement.Load(reader); _crewRoleIcons = element.Element("roles") .Elements() .ToDictionary(e => e.Name.ToString(), e => PackageImage.Load(_paths.GuiPackageFile, "gui/maps/icons/tankmen/roles/big/" + e.Element("icon").Value)); _crewRoleSmallIcons = element.Element("roles") .Elements() .ToDictionary(e => e.Name.ToString(), e => PackageImage.Load(_paths.GuiPackageFile, "gui/maps/icons/tankmen/roles/small/" + e.Element("icon").Value)); } }
public ImageSource GetClassSmallIcon(string @class) { return(_nationSmallIcons.GetOrCreate(@class, () => PackageImage.Load(_paths.GuiPackageFile, string.Format("gui/maps/icons/filters/tanks/{0}.png", @class)))); }
public ImageSource GetNationSmallIcon(string nationKey) { return(_nationSmallIcons.GetOrCreate(nationKey, () => PackageImage.Load(_paths.GuiPackageFile, string.Format("gui/maps/icons/filters/nations/{0}.png", nationKey)))); }
public int CreatePackageImage(PackageImage packageImage) { _db.PackageImages.Add(packageImage); _db.SaveChanges(); return(packageImage.Id); }
public async Task <ActionResult> Edit(CreatePackageViewModel data) { if (ViewBag.StudioID != data.studioid) { return(RedirectToAction("packagehome")); } if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid)) { return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" })); } if (ModelState.IsValid) { try { if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0) { TempData["error"] = "Invalid price setting"; data.images = db.Packages.Find(data.id).PackageImages.ToList(); return(View("editpackage", data)); } var edit = db.Packages.First(x => x.id == data.id); edit.depositprice = data.depoprice; edit.details = string.IsNullOrWhiteSpace(data.details) ? null : data.details; edit.name = data.name; edit.price = data.price; edit.studioid = data.studioid; var img = db.PackageImages.Where(x => x.PackageID == data.id); if (!string.IsNullOrWhiteSpace(data.ImgName)) { if (img == null || img.FirstOrDefault(x => x.ImageName.ToLower() == data.ImgName.ToLower()) == null) { AzureBlob BlobManagerObj = new AzureBlob(2); foreach (var item in img) { BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName)); } db.PackageImages.RemoveRange(img); PackageImage package = new PackageImage { ImageName = data.ImgName }; edit.PackageImages.Add(package); } } else { AzureBlob BlobManagerObj = new AzureBlob(2); foreach (var item in img) { BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName)); } db.PackageImages.RemoveRange(img); } db.SaveChanges(); await UpdateFirebaseOrder(edit); return(RedirectToAction("PackageHome")); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } return(View("editpackage", data)); }