You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.8 KiB
119 lines
3.8 KiB
using ValblazeProject.Models;
|
|
|
|
namespace ValblazeProject.Factories
|
|
{
|
|
public static class ItemFactory
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="imageContent"></param>
|
|
/// <returns></returns>
|
|
public static ItemModel ToModel(Item item, byte[] imageContent)
|
|
{
|
|
return new ItemModel
|
|
{
|
|
Id = item.Id,
|
|
DisplayName = item.DisplayName,
|
|
Name = item.Name,
|
|
RepairWith = item.RepairWith,
|
|
EnchantCategories = item.EnchantCategories,
|
|
MaxDurability = item.MaxDurability,
|
|
StackSize = item.StackSize,
|
|
ImageContent = imageContent,
|
|
ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public static Item Create(ItemModel model)
|
|
{
|
|
return new Item
|
|
{
|
|
Id = model.Id,
|
|
DisplayName = model.DisplayName,
|
|
Name = model.Name,
|
|
RepairWith = model.RepairWith,
|
|
EnchantCategories = model.EnchantCategories,
|
|
MaxDurability = model.MaxDurability,
|
|
StackSize = model.StackSize,
|
|
CreatedDate = DateTime.Now,
|
|
ImageBase64 = Convert.ToBase64String(model.ImageContent),
|
|
Num = 1
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="model"></param>
|
|
public static void Update(Item item, ItemModel model)
|
|
{
|
|
item.DisplayName = model.DisplayName;
|
|
item.Name = model.Name;
|
|
item.RepairWith = model.RepairWith;
|
|
item.EnchantCategories = model.EnchantCategories;
|
|
item.MaxDurability = model.MaxDurability;
|
|
item.StackSize = model.StackSize;
|
|
item.UpdatedDate = DateTime.Now;
|
|
item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public static Item Create(Item model)
|
|
{
|
|
return new Item
|
|
{
|
|
Id = model.Id,
|
|
DisplayName = model.DisplayName,
|
|
Name = model.Name,
|
|
RepairWith = model.RepairWith,
|
|
EnchantCategories = model.EnchantCategories,
|
|
MaxDurability = model.MaxDurability,
|
|
StackSize = model.StackSize,
|
|
CreatedDate = DateTime.Now,
|
|
ImageBase64 = model.ImageBase64,
|
|
Num = 1,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="model"></param>
|
|
public static void Update(Item item, Item model)
|
|
{
|
|
item.DisplayName = model.DisplayName;
|
|
item.Name = model.Name;
|
|
item.RepairWith = model.RepairWith;
|
|
item.EnchantCategories = model.EnchantCategories;
|
|
item.MaxDurability = model.MaxDurability;
|
|
item.StackSize = model.StackSize;
|
|
item.UpdatedDate = DateTime.Now;
|
|
item.ImageBase64 = model.ImageBase64;
|
|
item.Num = model.Num;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ajoute le numéro a un item
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="model"></param>
|
|
public static void Add1(Item item, Item model)
|
|
{
|
|
item.Num = model.Num + 1;
|
|
}
|
|
}
|
|
}
|