// GET: AttendancePayRate/Edit/5
        public async Task <ActionResult> Edit(Guid?id)
        {
            Permissions p    = new Permissions();
            bool        auth = p.isGranted(User.Identity.Name, this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + this.ControllerContext.RouteData.Values["action"].ToString());

            if (!auth)
            {
                return(new ViewResult()
                {
                    ViewName = "Unauthorized"
                });
            }
            else
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                AttendancePayRateModels attendancePayRateModels = await db.AttPayRate.FindAsync(id);

                if (attendancePayRateModels == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.listClient = new SelectList(db.Clients.Where(x => x.Active == true).OrderBy(x => x.CompanyName).ToList(), "Id", "CompanyName");
                ViewBag.idClient   = (from pr in db.AttPayRate
                                      join wt in db.WsTemplate on pr.RefId equals wt.Id
                                      join c in db.Clients on wt.Clients_Id equals c.Id
                                      where pr.Id == id
                                      select c.Id).Single();
                ViewBag.listWsTemplate = new SelectList(db.WsTemplate.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
                ViewBag.listAttStatus  = new SelectList(db.AttStatus.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
                return(View(attendancePayRateModels));
            }
        }
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            AttendancePayRateModels attendancePayRateModels = await db.AttPayRate.FindAsync(id);

            db.AttPayRate.Remove(attendancePayRateModels);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,RefId,AttendanceStatuses_Id,Amount,Notes,Active")] AttendancePayRateModels attendancePayRateModels)
        {
            if (ModelState.IsValid)
            {
                attendancePayRateModels.Id = Guid.NewGuid();
                db.AttPayRate.Add(attendancePayRateModels);
                await db.SaveChangesAsync();

                return(RedirectToAction("Create"));
            }

            ViewBag.listClient = new SelectList(db.Clients.Where(x => x.Active == true).OrderBy(x => x.CompanyName).ToList(), "Id", "CompanyName");
            //ViewBag.listWsTemplate = new SelectList(db.WsTemplate.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
            ViewBag.listAttStatus = new SelectList(db.AttStatus.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
            return(View(attendancePayRateModels));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,RefId,AttendanceStatuses_Id,Amount,Notes,Active")] AttendancePayRateModels attendancePayRateModels)
        {
            if (ModelState.IsValid)
            {
                db.Entry(attendancePayRateModels).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.listClient = new SelectList(db.Clients.Where(x => x.Active == true).OrderBy(x => x.CompanyName).ToList(), "Id", "CompanyName");
            ViewBag.idClient   = (from pr in db.AttPayRate
                                  join wt in db.WsTemplate on pr.RefId equals wt.Id
                                  join c in db.Clients on wt.Clients_Id equals c.Id
                                  where pr.Id == attendancePayRateModels.Id
                                  select c.Id).Single();
            ViewBag.listWsTemplate = new SelectList(db.WsTemplate.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
            ViewBag.listAttStatus  = new SelectList(db.AttStatus.Where(x => x.Active == true).OrderBy(x => x.Name).ToList(), "Id", "Name");
            return(View(attendancePayRateModels));
        }