Esempio n. 1
0
 public static FavoriteStrategyEntity ToEntity(this FavoriteStrategyModel FM)
 {
     if (FM != null)
     {
         FavoriteStrategyEntity FE = new FavoriteStrategyEntity();
         FE.StrategyId = FM.Strategy.Id;
         FE.UserId     = FM.User.Id;
         FE.Id         = FM.Id;
         FE.Active     = FM.Active;
         return(FE);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 2
0
 public static FavoriteStrategyModel ToModel(this FavoriteStrategyEntity FE)
 {
     if (FE != null)
     {
         StrategyRepository    repoEnre = new StrategyRepository();
         UserRepository        repoUtil = new UserRepository();
         FavoriteStrategyModel FM       = new FavoriteStrategyModel();
         FM.Strategy = repoEnre.GetOne(FE.StrategyId).ToModel();
         FM.User     = repoUtil.GetOne(FE.UserId).MapTo <UserModel>();
         FM.Id       = FE.Id;
         FM.Active   = FE.Active;
         return(FM);
     }
     else
     {
         return(null);
     }
 }
 public IActionResult Post(FavoriteStrategyModel Favori)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         if (Favori == null || Favori.User.Id == 0 || Favori.Strategy.Id == 0)
         {
             return(BadRequest());
         }
         else
         {
             repo.Create(Favori.ToEntity());
             return(Ok());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }
 public IActionResult Get(int id)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         FavoriteStrategyModel Objet = repo.GetOne(id)?.ToModel();
         if (Objet == null)
         {
             return(NotFound());
         }
         else
         {
             return(Ok(JsonConvert.SerializeObject(Objet)));
         }
     }
     else
     {
         return(Unauthorized());
     }
 }
 public IActionResult Put(int id, [FromBody] FavoriteStrategyModel Favori)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         if (repo.GetOne(id) == null)
         {
             return(NotFound());
         }
         else if (Favori == null || Favori.User.Id == 0 || Favori.Strategy.Id == 0)
         {
             return(BadRequest());
         }
         else
         {
             repo.Update(id, Favori.ToEntity());
             return(Ok());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }