Exemple #1
0
 public bool AddUser(User s)
 {
     try
     {
         if (s != null)
         {
             if (session1.Users.Any(u => u.Email.Equals(s.Email)))
             {
                 return(false);
             }
             s.ID = session1.Users.Max(u => u.ID) + 1;
             session1.Users.Add(s);
             session1.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public string LoginRecord(int userid, DateTime date, TimeSpan time)
 {
     try
     {
         UserActivity userActivity = new UserActivity();
         if (session1.UserActivities.Count() == 0)
         {
             userActivity.ID = 1;
         }
         else
         {
             userActivity.ID = session1.UserActivities.Max(ua => ua.ID) + 1;
         }
         userActivity.UserID     = userid;
         userActivity.Date       = date;
         userActivity.LogInTime  = time;
         userActivity.Confidence = Guid.NewGuid();
         session1.UserActivities.Add(userActivity);
         session1.SaveChanges();
         return(userActivity.Confidence.ToString());
     }
     catch (Exception ex)
     {
         return("");
     }
 }
 public ActionResult Create([Bind(Include = "ID,AssetSN,AssetName,DepartmentLocationID,EmployeeID,AssetGroupID,Description,WarrantyDate")] Asset asset)
 {
     if (ModelState.IsValid)
     {
         db.Assets.Add(asset);
         db.SaveChanges();
         return Json("Asset created successful!");
     }
     return Json("Unable to create asset!");
 }
Exemple #4
0
        private void labelExit_Click(object sender, EventArgs e)
        {
            var timeNow = DateTime.Now.TimeOfDay;

            session.Activities.Where(a => a.ID == ID).FirstOrDefault().FailReason = null;
            session.Activities.Where(a => a.ID == ID).FirstOrDefault().LogoutTime = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds);
            reportedCrash = true;
            session.SaveChanges();
            Close();
        }
        public ActionResult Create([Bind(Include = "userId,userName,userPw,userTypeIdFK")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(Json("User has been created."));
            }

            return(Json("error, user cannot be created. Please check your fields or try again."));
        }
        public ActionResult Create([Bind(Include = "resId,resName,resTypeIdFK,remainingQuantity")] Resource resource)
        {
            if (ModelState.IsValid)
            {
                db.Resources.Add(resource);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.resTypeIdFK = new SelectList(db.Resource_Type, "resTypeId", "resTypeName", resource.resTypeIdFK);
            return(View(resource));
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "allocId,resIdFK,skillIdFK")] Resource_Allocation resource_Allocation)
        {
            if (ModelState.IsValid)
            {
                db.Resource_Allocation.Add(resource_Allocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.resIdFK   = new SelectList(db.Resources, "resId", "resName", resource_Allocation.resIdFK);
            ViewBag.skillIdFK = new SelectList(db.Skills, "skillId", "skillName", resource_Allocation.skillIdFK);
            return(View(resource_Allocation));
        }
Exemple #8
0
        public ActionResult Create([Bind(Include = "ID,AssetID,TransferDate,FromAssetSN,ToAssetSN,FromDepartmentLocationID,ToDepartmentLocationID")] AssetTransferLog assetTransferLog)
        {
            if (ModelState.IsValid)
            {
                db.AssetTransferLogs.Add(assetTransferLog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AssetID = new SelectList(db.Assets, "ID", "AssetSN", assetTransferLog.AssetID);
            ViewBag.FromDepartmentLocationID = new SelectList(db.DepartmentLocations, "ID", "ID", assetTransferLog.FromDepartmentLocationID);
            ViewBag.ToDepartmentLocationID   = new SelectList(db.DepartmentLocations, "ID", "ID", assetTransferLog.ToDepartmentLocationID);
            return(View(assetTransferLog));
        }
Exemple #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string failText;

            if (radioButtonSoftwareCrash.Checked)
            {
                failText = $"Software Crash : {textBoxReason.Text}";
            }
            else
            {
                failText = $"System Crash : {textBoxReason.Text}";
            }

            using (var session = new Session1Entities())
            {
                var query = session.Activities.Where(a => a.UserID == id && a.FailReason == "CRASH").FirstOrDefault();

                query.FailReason = failText;
                try
                {
                    session.SaveChanges();
                    Close();
                }
                catch (DbEntityValidationException ex)
                {
                    var errorMessages    = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                    var fullErrorMessage = string.Join("\n", errorMessages);
                    var exceptionMessage = $"Error : {fullErrorMessage}";
                    MessageBox.Show(exceptionMessage);
                }
            }
        }
Exemple #10
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (CheckFields.CheckIfFieldsIsNotEmpty(this))
            {
                var row = adminMain.dataGridView.CurrentCell.OwningRow;
                // rowEmail is here so that there's no error about LINQ
                // not being able to convert it to LINQ expression
                // please don't remove it

                if (CheckFields.IsValidEmail(textBoxEmailAddress.Text))
                {
                    using (var session = new Session1Entities())
                    {
                        var rowEmail  = row.Cells["EmailAddress"].Value.ToString();
                        var rowSearch = session.Users.Where(u => u.Email == textBoxEmailAddress.Text).FirstOrDefault();
                        if (rowSearch == null || rowEmail == textBoxEmailAddress.Text)
                        {
                            // id is here so that there's no error about LINQ
                            // not being able to convert it to LINQ expression
                            // please don't remove it
                            var id      = int.Parse(row.Cells["ID"].Value.ToString());
                            var rowEdit = session.Users.Where(u => u.ID == id).FirstOrDefault();
                            rowEdit.Email     = textBoxEmailAddress.Text;
                            rowEdit.FirstName = textBoxFirstName.Text;
                            rowEdit.LastName  = textBoxLastName.Text;
                            rowEdit.OfficeID  = int.Parse(comboBoxOffice.SelectedValue.ToString());
                            rowEdit.RoleID    = radioButtonAdministrator.Checked ? 1 : 2;

                            try
                            {
                                session.SaveChanges();
                                adminMain.SetDatagridView();
                                Close();
                            }
                            catch (DbEntityValidationException ex)
                            {
                                var errorMessages    = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                                var fullErrorMessage = string.Join("\n", errorMessages);
                                var exceptionMessage = $"Error : {fullErrorMessage}";
                                MessageBox.Show(exceptionMessage);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Email Address has already been taken.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid email.");
                }
            }
            else
            {
                MessageBox.Show("Please don't leave any fields empty.");
            }
        }
Exemple #11
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (CheckFields.CheckIfFieldsIsNotEmpty(this))
     {
         var email = textBoxEmail.Text;
         if (CheckFields.IsValidEmail(email))
         {
             using (var session = new Session1Entities())
             {
                 if (session.Users.Where(u => u.Email == email).FirstOrDefault() == null)
                 {
                     var newUser = new User()
                     {
                         ID        = Utilities.GetLastUserID() + 1,
                         Email     = textBoxEmail.Text,
                         FirstName = textBoxFirstName.Text,
                         LastName  = textBoxLastName.Text,
                         OfficeID  = int.Parse(comboBoxOffice.SelectedValue.ToString()),
                         Birthdate = dateTimePickerBirthdate.Value,
                         Password  = Hash.MakeMd5(textBoxPassword.Text),
                         RoleID    = 2,
                         Active    = true
                     };
                     session.Users.Add(newUser);
                     try
                     {
                         session.SaveChanges();
                         adminMainForm.SetDatagridView();
                         ClearFields.ClearTextBoxes(this);
                         dateTimePickerBirthdate.ResetText();
                     }
                     catch (DbEntityValidationException ex)
                     {
                         var errorMessages    = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                         var fullErrorMessage = string.Join("\n", errorMessages);
                         var exceptionMessage = $"Error : {fullErrorMessage}";
                         MessageBox.Show(exceptionMessage);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Please enter another email :\nThat email is already used by another user");
                 }
             }
         }
         else
         {
             MessageBox.Show("Please Enter a valid email.");
         }
     }
     else
     {
         MessageBox.Show("Please fill all of the fields first.");
     }
 }
        public ActionResult Create([Bind(Include = "ID,AssetID,TransferDate,FromAssetSN,ToAssetSN,FromDepartmentLocationID,ToDepartmentLocationID")] AssetTransferLog assetTransferLog)
        {
            if (ModelState.IsValid)
            {
                db.AssetTransferLogs.Add(assetTransferLog);
                db.SaveChanges();
                return(Json("Successfully transfer Asset!"));
            }

            return(Json("Unable to transfer Asset!"));
        }
Exemple #13
0
        public ActionResult Create([Bind(Include = "ID,AssetID,TransferDate,FromAssetSN,ToAssetSN,FromDepartmentLocationID,ToDepartmentLocationID")] AssetTransferLog assetTransferLog)
        {
            if (ModelState.IsValid)
            {
                db.AssetTransferLogs.Add(assetTransferLog);
                db.SaveChanges();
                return(Json("Completed Transfer!"));
            }

            return(Json("Unable to transfer Asset! Please check and try again!"));
        }
        public ActionResult Create([Bind(Include = "ID,AssetSN,AssetName,DepartmentLocationID,EmployeeID,AssetGroupID,Description,WarrantyDate")] Asset asset)
        {
            if (ModelState.IsValid)
            {
                var findAssetName = (from x in db.Assets
                                     where x.AssetName == asset.AssetName && x.DepartmentLocationID == asset.DepartmentLocationID
                                     select x).FirstOrDefault();
                if (findAssetName != null)
                {
                    return(Json("Asset already exist in location!"));
                }
                else
                {
                    db.Assets.Add(asset);
                    db.SaveChanges();
                    return(Json("Successfully created Asset!"));
                }
            }

            return(View(asset));
        }
Exemple #15
0
        public ActionResult Create([Bind(Include = "ID,AssetSN,AssetName,DepartmentLocationID,EmployeeID,AssetGroupID,Description,WarrantyDate")] Asset asset)
        {
            if (ModelState.IsValid)
            {
                var findAsset = (from x in db.Assets
                                 where x.AssetName == asset.AssetName && x.DepartmentLocationID == asset.DepartmentLocationID
                                 select x).FirstOrDefault();
                if (findAsset != null)
                {
                    return(Json("Asset already exist in the location of choice!"));
                }
                else
                {
                    db.Assets.Add(asset);
                    db.SaveChanges();
                    return(Json("Created Asset!"));
                }
            }

            return(Json("Unable to create Asset! Please check and try again!"));
        }
        public ActionResult Create([Bind(Include = "ID,AssetID,AssetPhoto1")] AssetPhoto assetPhoto)
        {
            if (ModelState.IsValid)
            {
                var findPhoto = (from x in db.AssetPhotos
                                 where x.AssetID == assetPhoto.AssetID && x.AssetPhoto1 == assetPhoto.AssetPhoto1
                                 select x).FirstOrDefault();
                if (findPhoto != null)
                {
                    return(Json("Photo(s) saved successfully!"));
                }
                else
                {
                    db.AssetPhotos.Add(assetPhoto);
                    db.SaveChanges();
                    return(Json("Photo(s) saved successfully!"));
                }
            }


            return(Json("Unable to save photo(s)! Please try again later!"));
        }
Exemple #17
0
        private void buttonSuspendAccount_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentCell != null)
            {
                using (var session = new Session1Entities())
                {
                    // So that there's no LINQ error about
                    // not being able to convert to LINQ expression
                    var currentCellID = int.Parse(dataGridView.CurrentCell.OwningRow.Cells["ID"].Value.ToString());
                    var result        = session.Users.SingleOrDefault(u => u.ID == currentCellID);
                    result.Active = result.Active == true ? false : true;

                    session.SaveChanges();
                    SetDatagridView();
                }
            }
            else
            {
                MessageBox.Show("Please select a cell/row.");
            }
        }
Exemple #18
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            string username = textBoxUsername.Text;
            string password = textBoxPassword.Text;

            password = Hash.MakeMd5(password);
            using (var session = new Session1Entities())
            {
                var query = session.Users.Where(u => u.Email == username && u.Password == password);

                var result = query.FirstOrDefault();
                if (result != null)
                {
                    if (result.Active == true)
                    {
                        // Login Success
                        // Administrator = 1, User = 2
                        if (result.RoleID == 1)
                        {
                            var admin = new AdminMainForm();
                            // So that if AdminMainForm closed, LoginForm will open again

                            Hide();
                            admin.ShowDialog();
                            Show();
                        }
                        else
                        {
                            var user = new UserMainForm($"{result.FirstName} {result.LastName}", result.ID);
                            // So that if UserMainForm closed, LoginForm will open again

                            Hide();
                            var timeNow = DateTime.Now.TimeOfDay;
                            session.Activities.Add(new Activity {
                                UserID = result.ID, Date = DateTime.Now.Date, LoginTime = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds)
                            });
                            session.SaveChanges();
                            user.ShowDialog();
                            Show();
                        }

                        ClearFields.ClearTextBoxes(this);
                        failedLoginAttempt = 0;
                    }
                    else
                    {
                        MessageBox.Show("User suspended by Administrator!");
                        failedLoginAttempt++;
                        CheckLoginAttempt();
                    }
                }
                else
                {
                    // Login Failed

                    MessageBox.Show("Wrong Username or Password!");
                    failedLoginAttempt++;
                    CheckLoginAttempt();
                }
            }
        }