Exemplo n.º 1
0
        public ActionResult Index(FeedBackRelayViewModel x)
        {
            Batch newBatch = new Batch(); //\a Generates a new batch and adds it to database

            db.Batch.Add(newBatch);
            db.SaveChanges(); //\a
            if (x.BatchAll)   //\c if the batch all was checked then this sets
            {
                foreach (FeedBackForm form in x.Forms)
                {
                    var changedform = (from a in db.FeedBackForm where a.FeedbackID == form.FeedbackID select a).ToList()[0];
                    changedform.BatchID         = newBatch.BatchID;
                    db.Entry(changedform).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }// \c
            else    // \b if batchall is unchecked only set the batchid on the ones which are have indivudual checks
            {
                foreach (FeedBackForm form in x.Forms)//\b Checks the status of the bool on each individual form and sets the batch for each that are true to the previously generated batch
                {
                    if (form.toBatch)
                    {
                        var changedform = (from a in db.FeedBackForm where a.FeedbackID == form.FeedbackID select a).ToList()[0];
                        changedform.BatchID         = newBatch.BatchID;
                        db.Entry(changedform).State = EntityState.Modified;
                        db.SaveChanges();
                    } // \b
                }
            }
            return(RedirectToAction("Index", "Batches"));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            if (User.IsInRole("Admin"))
            {
                FeedBackRelayViewModel x            = new FeedBackRelayViewModel();
                FeedBackForm           feedBackForm = new FeedBackForm();
                x.Forms    = (from a in db.FeedBackForm where a.BatchID == null select a).OrderByDescending(p => p.DateofRide).ToList(); //gets all the forms that have not been batched and assigns them to the viewmodel
                x.BatchAll = false;                                                                                                      // initlaizeing the batchall variable in the viewmodel
                foreach (var item in x.Forms)
                {
                    var startDate = item.DateofRide; /*(from a in db.FeedBackForm where a.DateofRide == a.DateofRide select a)*/;
                    var endDate   = DateTime.Now;
                    var daysLeft  = (int)((endDate - startDate).TotalDays);
                    if (daysLeft >= 8)
                    {
                        item.isDanger = true;
                        x.HasDanger   = true;
                    }
                }

                return(View(x));
            }
            return(RedirectToAction("FeedBackIndex", "Manage"));
        }