Example #1
0
        private async Task Clone()
        {
            var wrapper = new JobOptionsWrapper {
                Options = jobOptions
            };
            var entity = new JobEntity
            {
                Owner        = await GuestRepo.Get(uid),
                CreationDate = DateTime.Now,
                JobType      = jobType,
                JobOptions   = JsonConvert.SerializeObject(wrapper, settings)
            };

            await JobRepo.Add(entity);

            // Get the entity that was just added in order to get its ID
            // entity = await JobRepo.GetAll().Include(j => j.Owner).OrderByDescending(e => e.Id).FirstAsync();

            try
            {
                var job = JobFactory.FromOptions(entity.Id, entity.Owner == null ? 0 : entity.Owner.Id, jobOptions);

                Manager.AddJob(job);
                Nav.NavigateTo($"job/{job.Id}");
            }
            catch (Exception ex)
            {
                await js.AlertException(ex);
            }
        }
        private async Task Edit()
        {
            var wrapper = new JobOptionsWrapper {
                Options = jobOptions
            };

            jobEntity.JobOptions = JsonConvert.SerializeObject(wrapper, settings);

            await JobRepo.Update(jobEntity);

            try
            {
                var oldJob = Manager.Jobs.First(j => j.Id == JobId);
                var newJob = JobFactory.FromOptions(JobId, jobEntity.Owner == null ? 0 : jobEntity.Owner.Id, jobOptions);

                Manager.Jobs.Remove(oldJob);
                Manager.Jobs.Add(newJob);
                Nav.NavigateTo($"job/{JobId}");
            }
            catch (Exception ex)
            {
                await js.AlertException(ex);
            }
        }