Ejemplo n.º 1
0
        public async Task <List <UserPlanModelResponse> > GetUSerPlanList(UserPlanModel userPlanModel)
        {
            var query = this.CreateQuery(userPlanModel);

            this.ExecutionQuery(query);
            await Task.Delay(1000);

            return(LstUserPlan);
        }
 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);
         }
     }
 }
Ejemplo n.º 3
0
        public StringBuilder CreateQuery(UserPlanModel userPlanModel)
        {
            StringBuilder sql    = new StringBuilder();
            StringBuilder end    = new StringBuilder();
            StringBuilder middle = new StringBuilder();

            sql.Append(" SELECT Users.Name, Plans.PlanName, Users.RegisterDate ");
            sql.Append(" FROM  Users ");
            middle.Append(" INNER JOIN Plans on Plans.IdUser = Users.ID ");
            end.Append(" WHERE ");
            var counter = 0;

            if (userPlanModel.Name != null && userPlanModel.Name != "")
            {
                end.Append(" Users.Name = '" + userPlanModel.Name.ToString() + "' ");
                counter = ++counter;
            }

            if (userPlanModel.RegisterDate != null && userPlanModel.RegisterDate != "")
            {
                if (counter > 0)
                {
                    end.Append(" AND Users.RegisterDate = '" + userPlanModel.RegisterDate.ToString() + "' ");
                }
                else
                {
                    end.Append(" Users.RegisterDate =  '" + userPlanModel.RegisterDate.ToString() + "' ");
                }
                counter = ++counter;
            }

            if (userPlanModel.CNPJ != null && userPlanModel.CNPJ != "")
            {
                if (counter > 0)
                {
                    end.Append(" AND Users.CNPJ = '" + userPlanModel.CNPJ.ToString() + "' ");
                }
                else
                {
                    end.Append(" Users.CNPJ = '" + userPlanModel.CNPJ.ToString() + "' ");
                }
                counter = ++counter;
            }

            if (userPlanModel.CPF != null && userPlanModel.CPF != "")
            {
                if (counter > 0)
                {
                    end.Append(" AND Users.CPF = '" + userPlanModel.CPF.ToString() + "' ");
                }
                else
                {
                    end.Append(" Users.CPF = '" + userPlanModel.CPF.ToString() + "' ");
                }
                counter = ++counter;
            }

            sql.Append(middle);

            if (counter > 0)
            {
                sql.Append(end);
            }


            return(sql);
        }
Ejemplo n.º 4
0
        public async Task <List <UserPlanModelResponse> > GetUSerPlanList(UserPlanModel userPlanModel)
        {
            var response = await this.getListUserPlanRepository.GetUSerPlanList(userPlanModel);

            return(response);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <List <UserPlanModelResponse> > > GetListUserPlan([FromBody] UserPlanModel userPlanModel)
        {
            DatabaseHelperClass databaseHelperClass = new DatabaseHelperClass("YOUR_CONNECTIONSTRING");

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Model is Invalid");
                }

                GetListUserPlanRepository getListUserPlanRepository = new GetListUserPlanRepository(databaseHelperClass);
                DbGetListUserPlan         dbGetListUserPlan         = new DbGetListUserPlan(getListUserPlanRepository);
                var response = await dbGetListUserPlan.GetUSerPlanList(userPlanModel);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                databaseHelperClass.connection.Close();
                return(StatusCode(500, "Internal Server Error"));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <List <UserPlanModelResponse> > > GetListUserPlan(UserPlanModel userPlanModel)
        {
            DatabaseHelperClass databaseHelperClass = new DatabaseHelperClass("Password=123456789;Persist Security Info=True;User ID=sqlserver;Initial Catalog=epharma;Data Source=34.95.222.223");

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Model is Invalid");
                }

                GetListUserPlanRepository getListUserPlanRepository = new GetListUserPlanRepository(databaseHelperClass);
                DbGetListUserPlan         dbGetListUserPlan         = new DbGetListUserPlan(getListUserPlanRepository);
                var response = await dbGetListUserPlan.GetUSerPlanList(userPlanModel);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                databaseHelperClass.connection.Close();
                return(StatusCode(500, "Internal Server Error"));
            }
        }