Ejemplo n.º 1
0
 public JsonMessageModel Post(TransactionModel model, string access_token = null)
 {
     if (!AuthorizeAccessToken(access_token).success)
     {
         return(AuthorizeAccessToken(access_token));
     }
     try
     {
         if (!ModelState.IsValid)
         {
             return new JsonMessageModel {
                        success = false, statusCode = (int)HttpStatusCode.OK, message = "model is valid!"
             }
         }
         ;
         model.CreatedOn = DateTime.UtcNow;
         var trans = model.ToEnity();
         //curent Config
         var config = _loyaltyConfigService.Find(x => x.Active)?.FirstOrDefault();
         if (config == null)
         {
             return new JsonMessageModel {
                        success = false, statusCode = (int)HttpStatusCode.OK, message = "Config is not found"
             }
         }
         ;
         //curentCard
         ///Lay config ra, quy doi diem thuong theo hang card, spent adjust ---> pointAdujust
         //spentAdjust-->config(spentAdjust*config)
         var SpentAdjust = trans.SpentAdjust;
         var div         = (float)(SpentAdjust) / config.ConfigValue;
         var PointAdjust = Math.Round((float)SpentAdjust / config.ConfigValue, 2);
         trans.PointAdjust = PointAdjust;
         var CardId = trans.LoyaltyCardId;
         var Card   = _loyaltyCardService.GetById(CardId);
         if (Card == null)
         {
             return new JsonMessageModel {
                        success = false, statusCode = (int)HttpStatusCode.OK, message = "Loyalty Card not Found found"
             }
         }
         ;
         Card.Point      += PointAdjust;
         Card.TotalSpent += SpentAdjust;
         //Cap nhat thong tin cho Card
         _loyaltyCardService.Update(Card);
         //Luu giao dich
         _transacitonService.Insert(trans);
         return(new JsonMessageModel {
             success = true, statusCode = (int)HttpStatusCode.OK, message = $"Trade {trans.Id} created!"
         });
     }
     catch (Exception e)
     {
         return(ExceptionReturnMessage(e));
     }
 }
 public HttpResponseMessage Post(LoyaltyCardTypeModel model)
 {
     try
     {
         var cardType = model.ToEnity();
         cardType.CreatedOn = DateTime.UtcNow;
         _loyaltyCardTypeService.Insert(cardType);
         return(Request.CreateResponse(HttpStatusCode.OK, $"CardType {cardType.Id} is Created!"));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
     }
 }
Ejemplo n.º 3
0
 public JsonMessageModel Post(ConfigModel model, string access_token = null)
 {
     if (!AuthorizeAccessToken(access_token).success)
     {
         return(AuthorizeAccessToken(access_token));
     }
     try
     {
         if (!ModelState.IsValid)
         {
             return new JsonMessageModel {
                        success = false, statusCode = (int)HttpStatusCode.ExpectationFailed, message = "Model state not Valid"
             }
         }
         ;
         var activeConfigs = _configService.Find(x => x.Active);
         var config        = model.ToEnity();
         config.Active    = true;
         config.CreatedOn = DateTime.UtcNow;
         _configService.Insert(config);
         if (activeConfigs != null && activeConfigs.Any())
         {
             foreach (var active in activeConfigs)
             {
                 active.Active = false;
                 _configService.Update(active);
             }
         }
         return(new JsonMessageModel {
             success = true, statusCode = (int)HttpStatusCode.OK, message = "New Config is created!", data = config.Id
         });
     }
     catch (Exception e)
     {
         return(ExceptionReturnMessage(e));
     }
 }