Ejemplo n.º 1
0
        public void PlanOnlyNameIdentifierEmpty()
        {
            this.plan = new Plan();
            var planDay = new PlanDay()
            {
                Name = "Day1"
            };

            this.plan.Planday = new System.Collections.Generic.List <PlanDay>
            {
                planDay,
            };

            var result = NextOrder.GetChoice(string.Empty, this.plan);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
Ejemplo n.º 2
0
 public void Init()
 {
     this.plan    = new Plan();
     this.planDay = new PlanDay()
     {
         Name = "Day1"
     };
     this.planDayMealLinsen = new PlanDayMeal()
     {
         Name       = "Linsen",
         Price      = 2.3,
         Restaurant = "LinsenWirt",
     };
     this.planDay.Meal1 = new System.Collections.Generic.List <PlanDayMeal>();
     this.planDay.Meal1.Add(this.planDayMealLinsen);
     this.plan.Planday = new System.Collections.Generic.List <PlanDay>
     {
         this.planDay,
     };
 }
Ejemplo n.º 3
0
        public async Task <ActionResult> SaveModify(PlanDayViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();

            try
            {
                using (PlanDayServiceClient client = new PlanDayServiceClient())
                {
                    PlanDay obj = new PlanDay()
                    {
                        Key = new PlanDayKey()
                        {
                            Year         = model.Year,
                            Month        = model.Month,
                            Day          = model.Day,
                            LocationName = model.LocationName != null ? model.LocationName : "",
                            ProductCode  = model.ProductCode != null ? model.ProductCode : ""
                        },

                        PlanQty             = model.PlanQty.ToString(),
                        PlanWatt            = model.PlanWatt,
                        PlanInQty           = model.PlanInQty,
                        TargetDebrisRate    = model.TargetDebrisRate,
                        PerCapitaEfficiency = model.PerCapitaEfficiency,
                        BeforePressQRate    = model.BeforePressQRate,
                        HProductARate       = model.HProductARate,
                        ProductARate        = model.ProductARate,
                        Editor     = User.Identity.Name,
                        EditTime   = DateTime.Now,
                        CreateTime = model.CreateTime,
                        Creator    = model.Creator
                    };

                    MethodReturnResult rst = await client.ModifyAsync(obj);

                    if (rst.Code == 0)
                    {
                        rst.Message = string.Format(PPMResources.StringResource.PlanDay_Modify_Success, obj.Key);
                    }
                    else
                    {
                        //数据错误
                        result.Code    = rst.Code;       //错误代码
                        result.Message = rst.Message;    //错误信息
                        result.Detail  = rst.Message;    //错误明细

                        return(Json(result));
                    }

                    return(Json(rst));
                }
            }
            catch (Exception e)
            {
                result.Code    = 1002;
                result.Message = e.Message;
                result.Detail  = e.ToString();

                return(Json(result));
            }
        }
Ejemplo n.º 4
0
        private async Task <DialogTurnResult> CompanyStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Get the Plan
            //try
            //{
            //    string food = BotMethods.GetDocument("eatingplan", "ButlerOverview.json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey);
            //    plan = JsonConvert.DeserializeObject<Plan>(food);
            //    dayId = plan.Planday.FindIndex(x => x.Name == DateTime.Now.DayOfWeek.ToString().ToLower());
            //    valid = true;
            //}
            //catch
            //{
            //    valid = false;
            //}

            IMealService mealService = new MealService(this.clientFactory.CreateClient(), this.botConfig.Value);
            var          meals       = await mealService.GetMeals(string.Empty, string.Empty);

            var mealEnumerator = meals.GetEnumerator();

            this.planDay = new PlanDay();
            while (mealEnumerator.MoveNext())
            {
                if (string.IsNullOrEmpty(this.planDay.Restaurant1))
                {
                    this.planDay.Restaurant1 = mealEnumerator.Current.Restaurant;
                }

                if (string.IsNullOrEmpty(this.planDay.Restaurant2) && this.planDay.Restaurant1 != mealEnumerator.Current.Restaurant)
                {
                    this.planDay.Restaurant2 = mealEnumerator.Current.Restaurant;
                }
            }


            stepContext.Values["name"] = stepContext.Context.Activity.From.Name;
            if (companyStatus == "extern")
            {
                stepContext.Values["companyStatus"] = companyStatus;
                return(await stepContext.NextAsync());
            }
            else
            {
                //if (DateTime.Now.IsDaylightSavingTime())
                //{

                //    if (DateTime.Now.Hour > 12)
                //    {
                //        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Es ist nach 12 Uhr. Bitte bestelle für einen anderen Tag."));
                //        return await stepContext.BeginDialogAsync(nameof(OrderForOtherDayDialog));
                //    }
                //}
                //else
                //{
                //    if (DateTime.Now.Hour + 1 > 12)
                //    {
                //        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Es ist nach 12 Uhr. Bitte bestelle für einen anderen Tag."));
                //        return await stepContext.BeginDialogAsync(nameof(OrderForOtherDayDialog));
                //    }
                //}


                return(await stepContext.PromptAsync(
                           nameof(ChoicePrompt),
                           new PromptOptions
                {
                    Prompt = MessageFactory.Text(nextOrderDialogWhoPrompt),
                    Choices = ChoiceFactory.ToChoices(new List <string> {
                        nextOrderDialogMyself, nextOrderDialogTrainee, nextOrderDialogCostumer
                    }),
                    Style = ListStyle.HeroCard,
                }, cancellationToken));
            }
        }
Ejemplo n.º 5
0
        public Model.PlanDay GetPastPlanDays(long userId, DateTime date)
        {
            var dailyInfoService = ObjectFactory.GetInstance <IDailyInfoService>();
            var viewDataService  = ObjectFactory.GetInstance <ITrainingSessionService>();
            var userService      = ObjectFactory.GetInstance <IUserService>();

            var trainingSession = viewDataService.GetTrainingSessionItems((int)userId)
                                  .Where(s => s.DateTrainingStart.Date.CompareTo(date.Date) == 0);// &&
            //            s.DateTrainingEnd.Date.CompareTo(date.Date) == 0);

            var dailyInfos = dailyInfoService.GetDayInfoViewService((int)userId, 1, date);

            var activities = new List <Activity>();

            if (dailyInfos.Hotel[0])
            {
                activities.Add(new Hotel());
            }
            if (dailyInfos.Rest[0])
            {
                activities.Add(new Rest());
            }
            if (dailyInfos.Travel[0])
            {
                activities.Add(new Travel());
            }
            if (dailyInfos.Weight[0] > 0)
            {
                activities.Add(new Weight(dailyInfos.Weight[0]));
            }
            if (dailyInfos.Sick[0] == true)
            {
                activities.Add(new Sick());
            }

            trainingSession.ToList().ForEach(session =>
            {
                var durationTimespan = session.DateTrainingEnd - session.DateTrainingStart;
                var duration         = 0;
                if (durationTimespan.TotalMinutes >= 30 && durationTimespan.TotalMinutes < 45)
                {
                    duration = 30;
                }
                if (durationTimespan.TotalMinutes >= 45 && durationTimespan.TotalMinutes < 60)
                {
                    duration = 30;
                }
                if (durationTimespan.TotalMinutes >= 60 && durationTimespan.TotalMinutes < 90)
                {
                    duration = 90;
                }
                if (durationTimespan.TotalMinutes >= 90 && durationTimespan.TotalMinutes <= 120)
                {
                    duration = 120;
                }


                GenericError error;
                var sportTypes        = userService.GetMasterUserSportsExtended(userId, out error);
                var selectedSportType = sportTypes.SportsList.SingleOrDefault(sport => sport.Id.Equals((long)session.SportId));
                int?s = ((selectedSportType != null) ? (int?)selectedSportType.Id : null);

                // activities.Add(new Training()
                // {
                //    DayPeriod = Convert.ToInt32(session.DayPeriod),
                //    Duration = durationTimespan.Minutes,
                //    EffortType = session.EffortId,
                //    FocusOn = session.TrainingTypeId,
                //    SportType = s
                //});
                var t        = new Training();
                t.DayPeriod  = Convert.ToInt32(session.DayPeriod);
                t.Duration   = durationTimespan.Minutes;
                t.EffortType = session.EffortId;
                t.FocusOn    = session.TrainingTypeId;
                t.SportType  = s;
                t.Notes      = session.Activity;
                //t.Notes = selectedSportType.LocalizedName;
                activities.Add(t);
            });

            var pastPlanDay = new PlanDay(date.Year, date.Month, date.Day, userId);

            pastPlanDay.Activities = activities;

            return(pastPlanDay);
        }
Ejemplo n.º 6
0
        private async Task <DialogTurnResult> TimeDayStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            IMealService mealService = new MealService(this.clientFactory.CreateClient(), this.botConfig.Value);
            var          meals       = await mealService.GetMeals(string.Empty, string.Empty);

            var     mealEnumerator = meals.GetEnumerator();
            PlanDay day            = new PlanDay();

            while (mealEnumerator.MoveNext())
            {
                if (string.IsNullOrEmpty(day.Restaurant1))
                {
                    day.Restaurant1 = mealEnumerator.Current.Restaurant;
                }

                if (string.IsNullOrEmpty(day.Restaurant2) && day.Restaurant1 != mealEnumerator.Current.Restaurant)
                {
                    day.Restaurant2 = mealEnumerator.Current.Restaurant;
                }
            }



            // Get the Plan
            try
            {
                string food = BotMethods.GetDocument("eatingplan", "ButlerOverview.json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey);
                plan  = JsonConvert.DeserializeObject <Plan>(food);
                dayId = plan.Planday.FindIndex(x => x.Name == DateTime.Now.DayOfWeek.ToString().ToLower());
                valid = true;
            }
            catch
            {
                valid = false;
            }

            OrderBlob orderBlob  = new OrderBlob();
            var       tmp        = BotMethods.GetSalaryDeduction("2", this.botConfig.Value.GetSalaryDeduction);
            int       weeknumber = (DateTime.Now.DayOfYear / 7) + 1;

            orderBlob = JsonConvert.DeserializeObject <OrderBlob>(BotMethods.GetDocument("orders", "orders_" + weeknumber + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));

            var nameID = orderBlob.OrderList.FindIndex(x => x.Name == stepContext.Context.Activity.From.Name);

            if (DateTime.Now.Hour - 1 >= 12)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Es ist schon nach 12 Uhr"));

                return(await stepContext.BeginDialogAsync(nameof(OrderForOtherDayDialog)));
            }
            else if (nameID != -1)
            {
                var temp = orderBlob.OrderList.FindAll(x => x.Name == stepContext.Context.Activity.From.Name);
                foreach (var item in temp)
                {
                    if (item.CompanyStatus.ToLower().ToString() == "für mich")
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Du hast heute schon etwas bestellt"));

                        return(await stepContext.BeginDialogAsync(nameof(NextOrder)));
                    }
                }

                return(await stepContext.NextAsync());
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initials the step asynchronous.
        /// </summary>
        /// <param name="stepContext">The step context.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>DialogTurnResult.</returns>
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text(overviewDialogHelp), cancellationToken);

            // Cards are sent as Attachments in the Bot Framework.
            // So we need to create a list of attachments for the reply activity.
            var attachments = new List <Attachment>();

            for (int i = 0; i < weekDaysEN.Length; i++)
            {
                if (weekDaysEN[i] == DateTime.Now.DayOfWeek.ToString().ToLower() && DateTime.Now.Hour < 12)
                {
                    indexer = i;
                }
                else if (weekDaysEN[i] == DateTime.Now.DayOfWeek.ToString().ToLower() && weekDaysEN[i] != "friday")
                {
                    indexer = i + 1;
                }
            }

            try
            {
                string food = BotMethods.GetDocument("eatingplan", "ButlerOverview.json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey);
                plan  = JsonConvert.DeserializeObject <Plan>(food);
                dayId = plan.Planday.FindIndex(x => x.Name == DateTime.Now.DayOfWeek.ToString().ToLower());
                valid = true;
            }
            catch
            {
                valid = false;
            }

            IMealService mealService = new MealService(this.clientFactory.CreateClient(), this.botConfig.Value);
            var          meals       = await mealService.GetMeals(string.Empty, string.Empty);

            var     mealEnumerator = meals.GetEnumerator();
            PlanDay day            = new PlanDay();

            while (mealEnumerator.MoveNext())
            {
                if (string.IsNullOrEmpty(day.Restaurant1))
                {
                    day.Restaurant1 = mealEnumerator.Current.Restaurant;
                }

                if (string.IsNullOrEmpty(day.Restaurant2) && day.Restaurant1 != mealEnumerator.Current.Restaurant)
                {
                    day.Restaurant2 = mealEnumerator.Current.Restaurant;
                }
            }

            List <string> restaurants = new List <string>();
            //var day = plan.Planday[dayId];
            //if (day.Restaurant1 != null)
            //{
            //    restaurants.Add(day.Restaurant1);
            //}

            //if (day.Restaurant2 != null)
            //{
            //    restaurants.Add(day.Restaurant2);
            //}

            string msg  = string.Empty;
            bool   temp = false;

            // TODO: What is the idea of this?
            foreach (var restaurant in restaurants)
            {
                if (temp == false)
                {
                    var otherDayDialog_Order1 = MessageFactory.Text(string.Format(otherDayDialogOrder, restaurant));
                    msg  = $" {otherDayDialog_Order1}";
                    temp = true;
                }
                else
                {
                    // TODO: ??
                }
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(""));

            // Reply to the activity we received with an activity.
            var reply = MessageFactory.Attachment(attachments);

            return(await stepContext.PromptAsync(
                       nameof(ChoicePrompt),
                       new PromptOptions
            {
                Prompt = MessageFactory.Text(overviewDialogWhatNow),
                Choices = ChoiceFactory.ToChoices(choices.ToList()),
                Style = ListStyle.HeroCard,
            }, cancellationToken));
        }