예제 #1
0
        // GET: Employee
        public async Task <ActionResult> Orders(string userID)
        {
            OrderView order = new OrderView();
            DbLevel   db    = new DbLevel();

            ApplicationUser AppUser = await UserManager.FindByIdAsync(userID);

            if (AppUser == null)
            {
                AppUser = UserManager.FindByName(User.Identity.GetUserId());
            }

            if (AppUser != null)
            {
                order.orders       = db.GetOrders(AppUser);
                order.employee     = db.GetEmployee(AppUser);
                order.OrderDetails = db.GetOrderDetails(AppUser);
            }
            else
            {
                ModelState.AddModelError("", "Something gone wrong");
            }

            return(View(order));
        }
예제 #2
0
        public ActionResult Change(int?pid, int?oid)
        {
            ApplicationUser AppUser = UserManager.FindByName(User.Identity.GetUserId());
            DbLevel         db      = new DbLevel();
            OrderDetail     od      =
                db.GetOrderDetails(AppUser, pid, oid).FirstOrDefault();

            return(View(od));
        }
        private void Initialize()
        {
            SetSession();
            GetConfigData();

            try
            {
                dbLevel1 = new DbLevel(Server, Port, Index, SearchRange, Session);
                dbLevel2 = new DbLevel(Server, Port, Index, SearchRange, Session);

                var result = LogStates.Success;
                try
                {
                    result = TestExistanceIOntology();
                }
                catch (Exception ex)
                {
                    result = LogStates.Nothing;
                }

                if (result.Id == LogStates.Nothing.Id)
                {
                    if (MessageBox.Show("The Database " + Index + "@" + Server + " does not exist. Should the Database be created?", "Create?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (CreateIndex().Id == LogStates.Error.Id)
                        {
                            MessageBox.Show("The Database cannot be created!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            result = LogStates.Success;
                        }
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }

                if (result.Id == LogStates.Success.Id)
                {
                }
            }
            catch (Exception ex)
            {
                // Config-Form
            }
        }
예제 #4
0
        public async Task <ActionResult> Register(Register login_)
        {
            if (ModelState.IsValid)
            {
                DbLevel         NW   = new DbLevel();
                Employees       empl = NW.GetEmployee(login_);
                ApplicationUser user = new ApplicationUser()
                {
                    UserName = login_.Email, FirstName = login_.FirstName, LastName = login_.LastName
                };


                NorthwindModel db = new NorthwindModel();

                if (empl != null)
                {
                    IdentityResult result = await UserManager.CreateAsync(user, login_.Password);

                    if (result.Succeeded)
                    {
                        login_.Message         = empl.FirstName + @" your account created. Login with your credentials";
                        TempData["Message"]    = login_.Message;
                        TempData["EmployeeID"] = empl.EmployeeID;
                        return(RedirectToAction("Login", "Validation"));
                    }

                    if (result.Errors != null && result.Errors.Count() != 0)
                    {
                        //String buillder ommitted for simplicity.
                        foreach (string error_ in  (from s in result.Errors select s))
                        {
                            login_.Message += " " + error_;
                        }

                        TempData["Message"] = login_.Message;
                        return(RedirectToAction("Register", "Validation"));
                    }
                }
                else
                {
                    TempData["Message"] = @"Employee not found. Are you working here?";
                    login_.Message      = TempData["Message"] as string;
                }
            }

            return(View(login_));
        }
예제 #5
0
        public async Task <ActionResult> Login(Login login_)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await UserManager.FindAsync(login_.Email, login_.Password);

                if (user != null)
                {
                    List <Claim> claims = new List <Claim>();
                    claims.Add(new Claim(ClaimTypes.NameIdentifier, login_.Email)); //, user.FirstName,user.LastName));
                    var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                    AuthenticationManager.SignIn(identity);

                    if (AuthenticationManager.AuthenticationResponseGrant.Identity.IsAuthenticated)
                    {
                        DbLevel   NW   = new DbLevel();
                        Employees empl = NW.GetEmployee(user);

                        if (empl != null)
                        {
                            TempData["Message"] = @"Welcome" + empl.FirstName + "!";
                            return(RedirectToAction("Orders", "Edit", new { userID = user.Id }));
                        }
                        else
                        {
                            TempData["Message"] = @"Something werid happened. No employee.";
                            return(View("Register", "Validation"));
                        }
                    }
                    else
                    {
                        TempData["Message"] = @"User not signed in";
                    }
                }
                else
                {
                    TempData["Message"] = @"Wrong password or username";
                }
            }

            login_.Message = TempData["Message"] as string;
            return(View(login_));
        }
예제 #6
0
        public ActionResult ChangePost(
            [Bind(Include = "ContactName,ProductName,Quantity,UnitPrice,productID,orderID")] OrderDetail od_)
        {
            ApplicationUser AppUser = UserManager.FindByName(User.Identity.GetUserId());
            DbLevel         db      = new DbLevel();

            try
            {
                db.SetOrderDetail(od_);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
            }

            OrderDetail od =
                db.GetOrderDetails(AppUser, od_.productID, od_.orderID).FirstOrDefault();

            return(RedirectToAction("Orders", "Edit"));
        }
예제 #7
0
 /// <summary>
 /// 查找库连接
 /// </summary>
 /// <returns></returns>
 public static KeyValuePair <string, DbBaseProvider> Find(DbLevel dbLevel)
 {
     return(dbProviders.Where(pair => pair.Value.ConnectionSetting.DbLevel == dbLevel).FirstOrDefault());
 }
예제 #8
0
 /// <summary>
 /// 查找库连接
 /// </summary>
 /// <returns></returns>
 public static KeyValuePair<string, DbBaseProvider> Find(DbLevel dbLevel)
 {
     return dbProviders.Where(pair => pair.Value.ConnectionSetting.DbLevel == dbLevel).FirstOrDefault();
 }