public ReturnMessage PostNewSubscriber(NewSubscriber newSubscriber) { GameData.Game gameVW; try { //var subscriber = new SubscriberRepository(_context, _NGSubscriptionsEntities); var mobileUser = _ISubscriberRepository.GetUserByPhoneNoWithoutExpDateCheck(newSubscriber.t); //If user subscription is expired if (mobileUser == null) { gameVW = new GameData.Game() { NetworkOperator = newSubscriber.nO, MSISDN = newSubscriber.t, SubDate = DateTime.Now, ExpDate = (newSubscriber.sT == 0) ? DateTime.Today.AddDays(7) : DateTime.Today.AddDays(1), Timestamped = DateTime.Now, Token = Guid.NewGuid().ToString().Substring(0, 7).ToUpper() }; return(new ReturnMessage() { ID = _ISubscriberRepository.PostNewSubscriber(gameVW), Message = $"Subscription Successful. Valid till: {gameVW.ExpDate.Value.ToShortDateString()}", Success = true }); } else { mobileUser.SubDate = DateTime.Now; mobileUser.ExpDate = (newSubscriber.sT == 0) ? (mobileUser.ExpDate < DateTime.Now) ? //if subscription is already expired DateTime.Now.AddDays(7) : // New Expiry Date is 7 days from today mobileUser.ExpDate.Value.AddDays(7) : //else New Expiry Date is 7 days from Old Expiry Date (mobileUser.ExpDate < DateTime.Now) ? //if subscription is already expired DateTime.Now.AddDays(1) : // New Expiry Date is 1 day from today mobileUser.ExpDate.Value.AddDays(1); //else New Expiry Date is 1 day from Old Expiry Date return(new ReturnMessage() { ID = _ISubscriberRepository.PostNewSubscriber(mobileUser), Message = $"Subscription Successful. Valid till: {mobileUser.ExpDate.Value.ToShortDateString()}", Success = true }); } } catch (Exception ex) { return(new ReturnMessage() { Success = false, Message = ex.Message }); } }
public static GameVM ToModel(this GameData.Game entity) { return(Mapper.Map <GameData.Game, GameVM>(entity)); }
public static GameData.Game ToEntity(this GameVM model, GameData.Game destination) { return(Mapper.Map(model, destination)); }