コード例 #1
0
ファイル: DietService.cs プロジェクト: vasIvanov/HealthStore
        public async Task <Diet> Update(Diet diet)
        {
            List <Task> tasks = new List <Task>();

            var planIdExists = _planRepository.GetById(diet.SuitablePlanId);

            tasks.Add(planIdExists);
            var idExists = _dietRepository.GetById(diet.Id);

            tasks.Add(idExists);
            var uniqueName = _dietRepository.GetByName(diet.Name);

            tasks.Add(uniqueName);

            await Task.WhenAll(tasks);

            if (planIdExists.Result != null && idExists.Result != null)
            {
                if ((uniqueName.Result != null && uniqueName.Result.Id == diet.Id) || uniqueName.Result == null)
                {
                    return(await _dietRepository.Update(diet));
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetById(long id)
        {
            var plan = await _planRepository.GetById(id);

            if (plan == null)
            {
                return(Ok("NoExiste"));
            }

            return(Ok(plan));
        }
コード例 #3
0
        public PlanForTrackingDto Get(FilterPlanTracking filterPlanTracking)
        {
            PlanForTrackingDto planForTracking = new PlanForTrackingDto();

            planForTracking.Plan = _planRepository.GetById(filterPlanTracking.IdPlan);

            List <VPlanGlobal> vPlanGlobal = _vPlanGlobalService.Get(filterPlanTracking);

            if (vPlanGlobal.Count > 0)
            {
                //recherche de tous les postes de la base et affectation au planTrackingDto
                planForTracking.Postes = GetPostesForTracking(vPlanGlobal, filterPlanTracking.IdPlan, filterPlanTracking.MonthYear.Month.Id == (int)EnumMonth.BalanceSheetYear);

                //somme pour le plan
                PlanTrackingAmountStoreDto planTrackingAmountStore = vPlanGlobal
                                                                     .GroupBy(x => new { x.PreviewAmount, x.IdPlan })
                                                                     .Select(g => new PlanTrackingAmountStoreDto {
                    Id = g.Key.IdPlan.Value, Label = planForTracking.Plan.Label, AmountPreview = g.Key.PreviewAmount.Value, AmountReal = g.Sum(a => a.AmountOperation.Value)
                })
                                                                     .GroupBy(x => new { x.Id })
                                                                     .Select(g => new PlanTrackingAmountStoreDto {
                    Id = g.Key.Id, Label = planForTracking.Plan.Label, AmountPreview = g.Sum(ap => ap.AmountPreview), AmountReal = g.Sum(a => a.AmountReal)
                })
                                                                     .First();

                planForTracking.AmountPreview = Math.Round(planTrackingAmountStore.AmountPreview, 2);
                planForTracking.AmountReal    = Math.Round(planTrackingAmountStore.AmountReal, 2);
                planForTracking.GaugeValue    = CalculatePercentage(planTrackingAmountStore.AmountReal, planTrackingAmountStore.AmountPreview);
            }


            return(planForTracking);
        }
コード例 #4
0
        public PayPal.Api.Plan GetPlan(int id)
        {
            var plan        = _planRepository.GetById(id);
            var planDetails = PayPal.Api.Plan.Get(_apiContext, plan.PlanId);

            return(planDetails);
        }
コード例 #5
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();
            }
        }
コード例 #6
0
        public ICommandResult Handle(UpdatePlanInput input)
        {
            var plan = _planRepository.GetById(input.Id);

            plan.Update(input.Name, input.ValueCents);

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

            if (validator.IsValid)
            {
                _planRepository.Create(plan);
                var body = new UpdatePlan(input.Name, input.Interval, input.IntervalType, Convert.ToInt32(input.ValueCents * 100), input.PayableWith);
                Requests.Put($"plans/{plan.Id}", body, Runtime.IuguApiToken);
            }

            return(new CommandResult("Plano atualizado com sucesso!", validator.Errors));
        }
コード例 #7
0
        public JsonResult Calculate(string sourceId, string destinyId, string planId, string time)
        {
            try
            {
                var _areaCodeValueMin = _contextAreaCodeValueMinute.ValueMin(int.Parse(sourceId), int.Parse(destinyId));
                var _plan             = _contextPlan.GetById(int.Parse(planId));
                var _speakMore        = SpeakMore.CalculateRate(_areaCodeValueMin, _plan, int.Parse(time));

                var json = JsonConvert.SerializeObject(_speakMore);

                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { error = true, responseText = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #8
0
        public void CreatesPlan_ShouldBeGetedPlan()
        {
            var planDto = new PlanDto()
            {
                Name                     = "",
                PaymentAmount            = "20",
                PaymentCycles            = "1",
                PaymentFrequency         = "1",
                PaymentCurrency          = "USD",
                PaymentFrequencyInterval = "monthly",
                OwnerId                  = 1,
                Description              = "Description"
            };

            var idPlan = _paymentService.CreatePlan(planDto);

            var createdPlan = _planRepository.GetById(idPlan);
            //Assert.Equals(planDto.Name, createdPlan.Name);
        }
コード例 #9
0
 public Plan Get(int id)
 {
     return(_planRepository.GetById(id));
 }
コード例 #10
0
        public OrderAddResponseDTO Add(OrderDTO orderDto, string role)
        {
            var order = new Order
            {
                EmployeeId  = orderDto.EmployeeId,
                IsDelivered = orderDto.IsDelivered,
                PlanId      = orderDto.PlanId,
                Shift       = orderDto.Shift,
                Plan        = _planRepository.GetById(orderDto.PlanId)
            };

            if ((DateTime.Now > order.Plan.EditableFrom && DateTime.Now <= order.Plan.EditableTo.AddHours(23).AddMinutes(59).AddSeconds(59)))
            {
                var orderDb = _orderRepository.GetByDateAndEmployee(order);
                if (orderDb == null)
                {
                    _orderRepository.Add(order);
                    return(new OrderAddResponseDTO {
                        Message = ""
                    });
                }
                else
                {
                    order.Id = orderDb.Id;
                    var differentShift = order.Shift != orderDb.Shift;

                    _orderRepository.Update(order);

                    if (differentShift)
                    {
                        return(new OrderAddResponseDTO {
                            Message = "Променет оброк за истиот датум од друга смена"
                        });
                    }
                    else
                    {
                        return(new OrderAddResponseDTO {
                            Message = ""
                        });
                    }
                }
            }
            else if (role == "HR")
            {
                var orderDb  = _orderRepository.GetByDateAndEmployee(order);
                var employee = _employeeRepository.GetById(order.EmployeeId);

                if (orderDb == null)
                {
                    _orderRepository.Add(order);
                    var emailBody = _emailManager.PrepareAddEmail(employee.Rfid, order.Plan.Date, order.Plan.Meal.Name, employee.Company.Name);
                    _emailManager.SendEmail("Додаден оброк", emailBody, employee.User.Email);
                    _emailManager.SendEmail("Додаден оброк", emailBody, "*****@*****.**");
                }
                else
                {
                    order.Id = orderDb.Id;
                    var oldMeal = orderDb.Plan.Meal.Name;

                    _orderRepository.Update(order);
                    var emailBody = _emailManager.PrepareEditEmail(employee.Rfid, order.Plan.Date, oldMeal, order.Plan.Meal.Name, employee.Company.Name);
                    _emailManager.SendEmail("Променет оброк", emailBody, employee.User.Email);
                    _emailManager.SendEmail("Додаден оброк", emailBody, "*****@*****.**");
                }


                return(new OrderAddResponseDTO {
                    Message = "Променет оброк надвор од периодот за промени"
                });
            }
            else
            {
                throw new Exception("Моментално сте надвор од периодот за избирање на овој оброк");
            }
        }
コード例 #11
0
 public async Task <CommandResult> GetById(int id)
 {
     return(new CommandResult(true, "Dados carregados com sucesso", await repository.GetById(id)));
 }
コード例 #12
0
 public void DeletePlan(int planID)
 {
     _planRepository.Delete(_planRepository.GetById(planID));
 }