示例#1
0
        public ICommandResult Handle(CreatePlanInput input)
        {
            var group = _groupRepository.GetById(input.GroupId);
            var plan  = new Plan(input.Name, group, input.ValueCents);

            plan.SetInterval(input.Interval, input.IntervalType);

            var validator = new PlanValidator().Validate(plan);

            if (validator.IsValid)
            {
                var body = new CreatePlan(input.Name, plan.Id.ToString(), input.Interval, input.IntervalType,
                                          Convert.ToInt32(input.ValueCents * 100), "credit_card");
                var result = JsonConvert.DeserializeObject <CreatePlanResult>(Requests.Post("plans", body, Runtime.IuguApiToken));
                plan.SetIuguId(result.Id);
                _planRepository.Create(plan);
            }

            return(new CommandResult("Plano criado com sucesso!", validator.Errors));
        }
示例#2
0
        public Plan Create(CreatePlanCommand command)
        {
            var plan = new Plan(command.ValueEquipmentMain, command.ValueEquipmentAdditional, command.ValueUpdate, command.Description, command.Title);

            plan.Create();
            _repository.Create(plan);

            if (Commit())
            {
                return(plan);
            }

            return(null);
        }
示例#3
0
        public async Task <Plan> Create(Plan plan)
        {
            List <Task> tasks    = new List <Task>();
            var         uniqueId = _planRepository.GetById(plan.Id);

            tasks.Add(uniqueId);
            var uniqueName = _planRepository.GetByName(plan.Name);

            tasks.Add(uniqueName);

            await Task.WhenAll(tasks);

            if (uniqueId.Result == null && uniqueName.Result == null)
            {
                return(await _planRepository.Create(plan));
            }
            else
            {
                throw new Exception();
            }
        }
示例#4
0
 public void Create(Plan plan)
 {
     _planRepository.Create(plan);
 }