Exemplo n.º 1
0
        public async Task <IActionResult> CreateNew([FromForm] FileInputModel model)
        {
            await HttpContext.Session.LoadAsync();

            string brandId  = HttpContext.Session.GetString("brandId");
            string username = HttpContext.Session.GetString("adminName");
            string imageUrl = await PostImage(model.FileToUpload, brandId);

            Image image = new Image();

            image.BrandId    = brandId;
            image.ImageId    = util.RandomString(5);
            image.ImageName  = model.Name;
            image.ImageLink  = imageUrl;
            image.Username   = username;
            image.CreateDate = DateTime.Now;

            imageRepository.Add(image);
            if (await imageRepository.SaveChangesAsync() >= 0)
            {
                return(RedirectToAction("ShowAll"));
            }

            return(View());
        }
        public async Task <IActionResult> CreateNew(Equipment equip)
        {
            equip.EquipmentId = util.RandomString(8);
            Equipment check;

            do
            {
                check = null;
                check = equipment.Get(equip.EquipmentId);
            }while (check != null);
            equip.EquipmentSercurityCode = util.RandomString(10);
            equip.CreateDate             = DateTime.Now;
            equip.Username = HttpContext.Session.GetString("adminName");

            equipment.Add(equip);
            await equipmentGroup.SaveChangesAsync();

            if (equip.Type == 2)
            {
                string url = "https://feedbackwebqr.azurewebsites.net/" + "Home/GetFeedback?equipmentId=" + equip.EquipmentId;
                return(RedirectToAction("ShowQR", new { qrText = url }));
            }
            return(RedirectToAction("ShowAll"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateNew(EquipmentGroup equipGroup)
        {
            equipGroup.EquipmentGroupId = util.RandomString(8);
            EquipmentGroup group;

            do
            {
                group = null;
                group = equipmentGroup.Get(equipGroup.EquipmentGroupId);
            }while (group != null);
            await HttpContext.Session.LoadAsync();

            equipGroup.CreateDate = DateTime.Now;
            equipGroup.Username   = HttpContext.Session.GetString("adminName");
            equipmentGroup.Add(equipGroup);
            return(RedirectToAction("ShowAll"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateNew(SurveyModel survey)
        {
            Feedback feedbackCheck;
            Feedback fb = JsonConvert.DeserializeObject <Feedback>(survey.Feedback);

            do
            {
                fb.FeedbackId = util.RandomString(8);
                feedbackCheck = null;
                feedbackCheck = feedback.Get(fb.FeedbackId);
            } while (feedbackCheck != null);
            feedback.Add(fb);
            await feedback.SaveChangesAsync();

            List <Question> listQuestion = JsonConvert.DeserializeObject <List <Question> >(survey.ListQuestion);

            foreach (Question ques in listQuestion)
            {
                ques.FeedbackId = fb.FeedbackId;
                ques.Username   = fb.Username;
                ques.Status     = 1;
                Question questionCheck;
                do
                {
                    ques.QuestionId = util.RandomString(7);
                    questionCheck   = null;
                    questionCheck   = question.Get(ques.QuestionId);
                } while (questionCheck != null);
                question.Add(ques);
                await question.SaveChangesAsync();
            }

            var    equipId = fb.EquipmentIds.Split(",");
            string tokens  = "";

            for (int i = 0; i < equipId.Length; i++)
            {
                if (equipId[i].Trim() != "")
                {
                    string token = await equipment.GetFCMTokenById(equipId[i].Trim());

                    tokens += token + "//";
                }
            }
            await _scheduler.Start();

            ITrigger trigger;

            var startDate = DateTime.Parse(fb.StartTime + "").ToUniversalTime();
            var endDate   = DateTime.Parse(fb.EndTime + "").ToUniversalTime();

            if (startDate <= DateTime.UtcNow && DateTime.UtcNow < endDate)
            {
                trigger = TriggerBuilder.Create()
                          .WithIdentity($"TriggerBegin-{DateTime.Now}")
                          .StartNow()
                          .WithPriority(1)
                          .Build();
            }
            else
            {
                trigger = TriggerBuilder.Create()
                          .WithIdentity($"TriggerBegin-{DateTime.Now}")
                          .StartAt(startDate)
                          .WithPriority(1)
                          .Build();
            }

            IJobDetail job = JobBuilder.Create <TaskBegin>()
                             .WithIdentity($"Job:{DateTime.Now}")
                             .Build();

            job.JobDataMap.Put("tokens", tokens);
            job.JobDataMap.Put("thanks", fb.ThanksSentenceId);
            job.JobDataMap.Put("gift", fb.GiftId);
            await _scheduler.ScheduleJob(job, trigger);

            ITrigger triggerEnd = TriggerBuilder.Create()
                                  .WithIdentity($"TriggerEnd-{DateTime.Now}")
                                  .StartAt(endDate)
                                  .WithPriority(1)
                                  .Build();

            IJobDetail jobEnd = JobBuilder.Create <TaskEnd>()
                                .WithIdentity($"JobEnd:{DateTime.Now}")
                                .Build();

            jobEnd.JobDataMap.Put("tokens", tokens);
            jobEnd.JobDataMap.Put("thanks", fb.ThanksSentenceId);
            jobEnd.JobDataMap.Put("gift", fb.GiftId);
            jobEnd.JobDataMap.Put("feedback", fb.FeedbackId);

            await _scheduler.ScheduleJob(jobEnd, triggerEnd);

            return(RedirectToAction("ShowAll"));
        }