Exemple #1
0
        private async Task createNewPlan(SuperiorPlan superiorPlan)
        {
            await new SuperiorPlanTDG().AddSuperiorPlanAsync(superiorPlan);
            SuperiorPlan newPlan = await new SuperiorPlanTDG().GetLatestSuperiorPlanByIdOwner(IdOwner);

            IdPlan = newPlan.Id;
        }
        public async Task PatchSuperiorPlanAsync(SuperiorPlan superiorPlan)
        {
            var client = RefitClient.Service;

            Dictionary <string, object> dict = new Dictionary <string, object>
            {
                { "status", superiorPlan.Status }
            };

            client.PatchSuperiorPlan(superiorPlan.Id, dict, superiorPlan.Etag);
        }
Exemple #3
0
        public NewProductionPlanForm()
        {
            var settings = Properties.Settings.Default;

            IdOwner = settings.idUser;
            InitializeComponent();
            SuperiorPlan superiorPlan = new SuperiorPlan
            {
                IdOwner = IdOwner,
                Status  = "pending"
            };

            createNewPlan(superiorPlan);
        }
        public async Task AddSuperiorPlanAsync(SuperiorPlan superiorPlan)
        {
            var      client    = RefitClient.Service;
            DateTime now       = DateTime.UtcNow;
            var      nowString = now.ToString("dd/MM/yy HH:mm:ss", CultureInfo.InvariantCulture);
            Dictionary <string, object> dict = new Dictionary <string, object>
            {
                { "owner", superiorPlan.IdOwner },
                { "status", superiorPlan.Status },
                { "created", nowString }
            };

            await client.CreateSuperiorPlan(dict);
        }
        private async void generateProductionPlanButton_Click(object sender, EventArgs e)
        {
            settings = Properties.Settings.Default;
            MyParams myParams;

            // Hledame nejnovejsi plan, ktery je od prihlaseneho uzivatele a je active
            myParams = new MyParams
            {
                Query = $"{{\"$and\":[{{\"owner\": \"{settings.idUser}\"}},{{\"status\":\"active\"}}]}}",
                Limit = "1",
                Sort  = "-created"
            };
            SuperiorPlan activePlan = (await new SuperiorPlanTDG().GetSuperiorPlansAsync(myParams))[0];

            activePlan.Status = "done";

            // Hledame nejnovejsi plan, ktery je od prihlaseneho uzivatele a je pending
            myParams = new MyParams
            {
                Query = $"{{\"$and\":[{{\"owner\": \"{settings.idUser}\"}},{{\"status\":\"pending\"}}]}}",
                Limit = "1",
                Sort  = "-created"
            };
            SuperiorPlan pendingPlan = (await new SuperiorPlanTDG().GetSuperiorPlansAsync(myParams))[0];

            pendingPlan.Status = "active";

            List <Shift> shifts = await new ShiftTDG().GetShiftsByIdSuperiorPlanAsync(pendingPlan.Id);
            Random       rnd    = new Random();

            foreach (Shift shift in shifts)
            {
                bool changed = false;
                while (shift.IdWorkers.Count > shift.WorkersCount)
                {
                    changed = true;
                    shift.IdWorkers.RemoveAt(rnd.Next(0, shift.IdWorkers.Count));
                }
                if (changed)
                {
                    new ShiftTDG().PatchShiftAsync(shift);
                }
            }
            new SuperiorPlanTDG().PatchSuperiorPlanAsync(pendingPlan);
            new SuperiorPlanTDG().PatchSuperiorPlanAsync(activePlan);
        }
        public async Task <SuperiorPlan> GetSuperiorPlanByIdAsync(string id)
        {
            var myParams = new MyParams {
                Query = $"{{\"_id\":\"{id}\"}}"
            };
            var client = RefitClient.Service;
            var result = await client.GetSuperiorPlan(id);

            SuperiorPlan superiorPlan = new SuperiorPlan
            {
                Id       = result.Id,
                Etag     = result.Etag,
                Status   = result.Status,
                IdShifts = result.IdShifts,
                IdOwner  = result.IdOwner,
                Created  = result.Created
            };

            return(superiorPlan);
        }
        public async Task <List <SuperiorPlan> > GetSuperiorPlansAsync(MyParams myParams)
        {
            var client = RefitClient.Service;
            var result = await client.GetSuperiorPlans(myParams);

            List <SuperiorPlan> superiorPlans = new List <SuperiorPlan>();

            foreach (SuperiorPlan res in result.SuperiorPlans)
            {
                SuperiorPlan sp = new SuperiorPlan
                {
                    Id       = res.Id,
                    Etag     = res.Etag,
                    Status   = res.Status,
                    IdShifts = res.IdShifts,
                    IdOwner  = res.IdOwner,
                    Created  = res.Created
                };
                superiorPlans.Add(sp);
            }
            return(superiorPlans);
        }
 public async Task DeleteSuperiorPlanAsync(SuperiorPlan superiorPlan)
 {
     throw new NotImplementedException();
 }