Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "USERID,STAFFCODE,STAMP")] HKLOGINMAP hKLOGINMAP)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    hKLOGINMAP.STAMP           = hKLOGINMAP.STAMP + 1;
                    db.Entry(hKLOGINMAP).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }
            ViewBag.USERID    = new SelectList(db.SAUSERMs, "USERID", "USERID", hKLOGINMAP.USERID);
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs.Select(x => new { STAFFCODE = x.STAFFCODE, STAFFDESC = "(" + x.STAFFCODE + ") " + x.STAFFDESC }), "STAFFCODE", "STAFFDESC", hKLOGINMAP.STAFFCODE);
            return(View(hKLOGINMAP));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(string id)
        {
            HKLOGINMAP hKLOGINMAP = db.HKLOGINMAPs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            try
            {
                db.HKLOGINMAPs.Remove(hKLOGINMAP);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        //string message = string.Format("{0}:{1}",
                        //    validationErrors.Entry.Entity.ToString(),
                        //   validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                UpdateException updateException = (UpdateException)ex.InnerException;
                if (updateException != null)
                {
                    if (updateException.InnerException != null)
                    {
                        var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                        foreach (var error in sqlException.Errors)
                        {
                            if (error.Message != null)
                            {
                                ModelState.AddModelError(string.Empty, error.Message);
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, updateException.Message);
                }
            }

            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs.Select(x => new { STAFFCODE = x.STAFFCODE, STAFFDESC = "(" + x.STAFFCODE + ") " + x.STAFFDESC }), "STAFFCODE", "STAFFDESC", hKLOGINMAP.STAFFCODE);
            return(View(hKLOGINMAP));
        }
Ejemplo n.º 3
0
        // GET: HKLOGINMAPs/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HKLOGINMAP hKLOGINMAP = db.HKLOGINMAPs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (hKLOGINMAP == null)
            {
                return(HttpNotFound());
            }
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs.Select(x => new { STAFFCODE = x.STAFFCODE, STAFFDESC = "(" + x.STAFFCODE + ") " + x.STAFFDESC }), "STAFFCODE", "STAFFDESC", hKLOGINMAP.STAFFCODE);
            return(View(hKLOGINMAP));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                HKLOGINMAP staffrec = db.HKLOGINMAPs.Find(model.UserName);

                if (staffrec != null)
                {
                    HKSTAFF staff      = db.HKSTAFFs.Find(staffrec.STAFFCODE);
                    var     Descendent = staff.Descendent;
                    Session["HKSTAFF"] = staffrec.STAFFCODE;
                    string stafflist = "";

                    if (Descendent.Count() > 1)
                    {
                        foreach (HKSTAFF item in Descendent)
                        {
                            if (stafflist == string.Empty)
                            {
                                stafflist = "'" + item.STAFFCODE + "'";
                            }
                            else
                            {
                                stafflist = stafflist + ",'" + item.STAFFCODE + "'";
                            }
                        }
                        Session["HKSTAFFLIST"] = stafflist;
                        Session["HKSTAFFDB"]   = Descendent;
                    }
                }
                //using (HKSTAFFsController hc = new HKSTAFFsController() )
                //{
                //   return hc.StaffList(Descendent);
                //}
                if (returnUrl == null)
                {
                    return(RedirectToAction("Work", "Home"));
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }