Beispiel #1
0
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                List <ScheduleViewmodel> CustomerVMlist = new List <ScheduleViewmodel>(); // to hold list of Customer and order details


                var schedulelist = (from bb in _context.MemberEnrol join aa in _context.Schedules on bb.ScheduleId equals aa.Id join cc in _context.Users on aa.Coach equals cc.Email select new { Date = aa.Date, CoachName = cc.Fname, Coach = cc.Id, Time = aa.Time, Location = aa.Location, Day = aa.Day, Member = bb.Member, Id = aa.Id }).ToList();

                //query getting data from database from joining two tables and storing data in customerlist

                foreach (var item in schedulelist)

                {
                    ScheduleViewmodel objcvm = new ScheduleViewmodel(); // ViewModel

                    objcvm.Id = item.Id;

                    objcvm.Date = item.Date;

                    objcvm.Time = item.Time;

                    objcvm.Coach = item.Coach;

                    objcvm.CoachName = item.CoachName;

                    objcvm.Day = item.Day;

                    objcvm.Member = item.Member;

                    objcvm.Location = item.Location;

                    CustomerVMlist.Add(objcvm);
                }

                //Using foreach loop fill data from custmerlist to List<CustomerVM>.

                return(View(CustomerVMlist)); //List of CustomerVM (ViewModel)
            }
            else
            {
                return(Redirect("../Identity/Account/Login"));
            }
        }
Beispiel #2
0
        // GET: Schedules/Create
        public IActionResult Create()
        {
            List <ScheduleViewmodel> CustomerVMlist = new List <ScheduleViewmodel>(); // to hold list of Customer and order details


            var schedulelist = (from bb in _context.Users join aa in _context.UserRoles on bb.Id equals aa.UserId join cc in _context.Roles on aa.RoleId equals cc.Id where cc.Name == "Coach" select new { CoachName = bb.Fname, Coach = bb.Id }).ToList();

            //query getting data from database from joining two tables and storing data in customerlist

            foreach (var item in schedulelist)

            {
                ScheduleViewmodel objcvm = new ScheduleViewmodel(); // ViewModel
                objcvm.Coach = item.Coach;

                objcvm.CoachName = item.CoachName;

                CustomerVMlist.Add(objcvm);
            }

            ViewData["coaches"] = CustomerVMlist;
            return(View());
        }