public async Task <ActionResult> SetInActive(int id)
        {
            try
            {
                CommitteeModel committeemodel = await db.Committees.FindAsync(id);

                committeemodel.CurrentStatus   = CurrentStatus.Past;
                db.Entry(committeemodel).State = EntityState.Modified;

                var committeehistory = from comHistory in db.ConsumerRepCommitteeHistory
                                       where comHistory.CommitteeModelID == committeemodel.CommitteeModelID
                                       select comHistory;


                foreach (var comHistory in committeehistory)
                {
                    comHistory.FinishedDate    = DateTime.Today;
                    db.Entry(comHistory).State = EntityState.Modified;

                    ConsumerRepModel consumerRep = db.ConsumerReps.Find(comHistory.ConsumerRepModelID);
                    consumerRep.EndorsementStatus = EndorsementStatus.InActive;
                    db.Entry(consumerRep).State   = EntityState.Modified;
                }

                await db.SaveChangesAsync();
            }
            catch (DataException /* dex */)
            {
                return(RedirectToAction("SetInActive", new { id = id, saveChancesError = true }));
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> AddToCommittee([Bind(Include = "ConsumerRepCommitteeHistoryModelID,CommitteeModelID,ConsumerRepModelID,PrepTime,Meetingtime,EndorsementStatus,EndorsementDate,EndorsementType")] ConsumerRepCommitteeHistoryModel consumerrepcommitteehistorymodel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    consumerrepcommitteehistorymodel.ReportedDate = DateTime.Today;

                    CommitteeModel committee = db.Committees.Find(consumerrepcommitteehistorymodel.CommitteeModelID);
                    committee.CurrentStatus   = CurrentStatus.Current;
                    db.Entry(committee).State = EntityState.Modified;

                    ConsumerRepModel consumer = db.ConsumerReps.Find(consumerrepcommitteehistorymodel.ConsumerRepModelID);
                    consumer.EndorsementStatus = EndorsementStatus.Active;
                    db.Entry(consumer).State   = EntityState.Modified;

                    db.ConsumerRepCommitteeHistory.Add(consumerrepcommitteehistorymodel);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details/" + consumerrepcommitteehistorymodel.ConsumerRepModelID, "ConsumerRepModel"));
                }
            }
            catch (DataException /* dex */)
            {
                // Log the error
                ModelState.AddModelError("", "Unable to save changes. Please Try Again.");
            }

            ViewBag.CommitteeModelID   = new SelectList(db.Committees, "CommitteeModelID", "CommitteeName");
            ViewBag.ConsumerRepModelID = consumerrepcommitteehistorymodel.ConsumerRepModelID;
            return(View());
        }
        // GET: /ConsumerRepModel/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ConsumerRepModel consumerrepmodel = await db.ConsumerReps.FindAsync(id);

            if (consumerrepmodel == null)
            {
                return(HttpNotFound());
            }
            return(View(consumerrepmodel));
        }
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                ConsumerRepModel consumerrepmodel = await db.ConsumerReps.FindAsync(id);

                db.ConsumerReps.Remove(consumerrepmodel);
                await db.SaveChangesAsync();
            }
            catch (DataException /* dex */)
            {
                //Log the error
                return(RedirectToAction("Delete", new { id = id, saveChangesError = true }));
            }
            return(RedirectToAction("Index"));
        }
        // GET: /ConsumerRepModel/Delete/5
        public async Task <ActionResult> Delete(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Delete failed. Please Try Again";
            }
            ConsumerRepModel consumerrepmodel = await db.ConsumerReps.FindAsync(id);

            if (consumerrepmodel == null)
            {
                return(HttpNotFound());
            }
            return(View(consumerrepmodel));
        }
        public ActionResult Create(CreateCommitteeViewModel vm)
        {
            try
            {
                //if (ModelState.IsValid)
                //{
                vm.NewCommitteeModel.CurrentStatus = CurrentStatus.Current;
                db.Committees.Add(vm.NewCommitteeModel);

                vm.NewConsumerRepCommitteeHistoryModel.ReportedDate = DateTime.Today;

                vm.NewConsumerRepCommitteeHistoryModel.CommitteeModelID = vm.NewCommitteeModel.CommitteeModelID;
                db.ConsumerRepCommitteeHistory.Add(vm.NewConsumerRepCommitteeHistoryModel);

                vm.NewCommitteeAreaOfHealthModel.CommitteeModelID = vm.NewCommitteeModel.CommitteeModelID;
                db.CommitteeModel_CommitteeAreaOfHealth.Add(vm.NewCommitteeAreaOfHealthModel);

                ConsumerRepModel consumer = db.ConsumerReps.Find(vm.NewConsumerRepCommitteeHistoryModel.ConsumerRepModelID);
                consumer.EndorsementStatus = EndorsementStatus.Active;
                db.Entry(consumer).State   = EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("Index"));
                //}
            }
            catch (DataException /* dex */)
            {
                // Log the error
                ModelState.AddModelError("", "Unable to save the chances. Please try again.");
            }

            vm = new CreateCommitteeViewModel
            {
                NewCommitteeModel = new CommitteeModel(),
                NewConsumerRepCommitteeHistoryModel = new ConsumerRepCommitteeHistoryModel(),
                NewCommitteeAreaOfHealthModel       = new CommitteeModel_CommitteeAreaOfHealthModel(),
                ConsumerRepsID           = new SelectList(db.ConsumerReps, "ConsumerRepModelID", "FullName"),
                CommitteeAreasOfHealthID = new SelectList(db.CommitteeAreaOfHealth, "CommitteeAreaOfHealthModelID", "AreaOfHealthName")
            };

            return(View(vm));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ConsumerRepModelID,FirstName,LastName,MemberStatus,EndorsementStatus,DateTrained")] ConsumerRepModel consumerrepmodel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(consumerrepmodel).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /* dex */)
            {
                // Log the error here with dex var
                ModelState.AddModelError("", "Unable to save changes. Please try again.");
            }
            return(View(consumerrepmodel));
        }