Пример #1
0
        public ActionResult Create([Bind(Include = "STAFFCODE,STAFFDESC,STAFFLEVEL,MSTRSTAFF,REFCNT,STAMP")] HKSTAFF hKSTAFF)
        {
            if (ModelState.IsValid)
            {
                hKSTAFF.STAMP = 0;
                try
                {
                    db.HKSTAFFs.Add(hKSTAFF);
                    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);
                    }
                }
            }

            return(View(hKSTAFF));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(string id)
        {
            HKSTAFF hKSTAFF = db.HKSTAFFs.Find(id);

            try
            {
                db.HKSTAFFs.Remove(hKSTAFF);
                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);
                }
            }
            return(View(hKSTAFF));
        }
Пример #3
0
        // GET: HKSTAFFs/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HKSTAFF hKSTAFF = db.HKSTAFFs.Find(id);

            if (hKSTAFF == null)
            {
                return(HttpNotFound());
            }
            return(View(hKSTAFF));
        }
Пример #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));
            }
        }