public async Task <IActionResult> AddPlan([FromBody] AddPlanModel model)
        {
            try
            {
                model.UserId = CurrentUserId;

                var result = await planLib.AddPlanAsync(model);

                return(CustomResult(result));
            }
            catch (System.Exception exp)
            {
                return(CustomError(exp));
            }
        }
示例#2
0
        public async Task <PlanModel> AddPlanAsync(AddPlanModel model)
        {
            var entity = new Plan
            {
                Description = model.Description,
                EndDate     = model.EndDate,
                Name        = model.Name,
                StartDate   = model.StartDate,
                UserId      = model.UserId
            };

            await planRepo.AddAsync(entity);

            await unitOfWork.CommitAsync();

            return(ConvertEntityToPlanModel(entity));
        }
 public bool addPlan(AddPlanModel user)
 {
     if (!isValidateApiUser(user.token))
     {
         return(false);
     }
     using (db)
     {
         try
         {
             PlanModel p = db.Plans.Find(user.id);
             if (p == null)
             {
                 return(false);
             }
             UserPlanModel up  = new UserPlanModel();
             int           max = 0;
             foreach (UserPlanModel t in db.UserPlans.Where(u => u.username == user.username))
             {
                 if (t != null && t.priority > max)
                 {
                     max = t.priority;
                 }
             }
             up.id               = user.id;
             up.username         = user.username;
             up.expiryTime       = DateTime.Now.AddDays(p.validity);
             up.storageRemaining = p.storageBenefit;
             up.subTime          = DateTime.Now;
             up.priority         = max + 1;
             db.UserPlans.Add(up);
             db.SaveChanges();
             return(true);
         }catch (Exception e)
         {
             Console.WriteLine(e.Message);
             return(false);
         }
     }
 }