Esempio n. 1
0
        //  [ValidateAntiForgeryToken]
        public ActionResult Details(EmployeeDetailsViewItem EmployeeDetails,  string id, string Lastname, string LastName)
        {
            try
            {
                //context.Entry(Roles).State = System.Data.Entity.EntityState.Modified;
                //context.SaveChanges();

                _dbq.ChangeRole(id, EmployeeDetails.RoleName);

                if (EmployeeDetails.ShiftGroupPartnerName == null)
                {
                    return RedirectToAction("Index");
                }
                if (_dbq.CheckForShiftgroup(id) == true)
                {
                    _dbq.DeleteShiftGroup(id);
                }
                ShiftGroup UpdateShiftGroup = new ShiftGroup(EmployeeDetails.ShiftGroupPartnerName, id);
                _dbq.InsertNewShiftgroup(UpdateShiftGroup);

                

                EmployeeDetails.UserId = id;
                _dbq.UpdateEmployeebyDetail(EmployeeDetails);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 2
0
        public Boolean UpdateEmployeebyDetail(EmployeeDetailsViewItem Emp)
        {
            int ShiftGroupIdtmp = SelectShiftGroupId(Emp.UserId);

            bool Result = false;
            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {
                string sqlStatement =
                    "UPDATE dbo.AspNetUsers SET UserName = @UserName, FirstName = @FirstName, LastName = @LastName, Email = @EMail, ShiftGroupID = @ShiftGroupId WHERE Id = @Id";
                using (SqlCommand cmd = new SqlCommand(sqlStatement, connection))
                {
                    cmd.Parameters.AddWithValue("UserName", Emp.UserName);
                    cmd.Parameters.AddWithValue("FirstName", Emp.FirstName);
                    cmd.Parameters.AddWithValue("LastName", Emp.LastName);
                    cmd.Parameters.AddWithValue("Email", Emp.Email);
                    cmd.Parameters.AddWithValue("ShiftGroupId", ShiftGroupIdtmp);
                    cmd.Parameters.AddWithValue("Id", Emp.UserId);

                    try
                    {
                        connection.Open();
                        cmd.ExecuteNonQuery();
                        Result = true;
                    }
                    catch (SqlException e)
                    {
                        {
                            Result = false;
                        }
                    }
                }
            }
            return Result;
        }
Esempio n. 3
0
        public void SelectEmployeebyDetailsById()
        {
            string id = "bff0f95a-5b1a-42cc-a1cc-8f520477c37a";
            EmployeeDetailsViewItem emp;
            string Idtmp = "";
            string Usernametmp = "";
            string FirstNametmp = "";
            string LastNametmp = "";
            string Emailtmp = "";
            string RoleName = "";
            string ShiftGroupPartnerName = "";
            string DivisonName = "";
            int ShiftGroupIDtmp = 0;
            int DivisionIDtmp = 0;

            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {

                string sqlStatement =
                    "SELECT UserName, FirstName, LastName, Email, ShiftGroupID, DivisionID FROM [dbo].AspNetUsers WHERE Id= @EmployeeID";
                using (SqlCommand cmd = new SqlCommand(sqlStatement, connection))
                {
                    cmd.Parameters.AddWithValue("EmployeeID", "1e04bd54-4fb8-4bb8-806c-8ad7b8c90c43");
                    connection.Open();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        // Check if the reader has any rows at all before starting to read.
                        if (reader.HasRows)
                        {
                            // Read advances to the next row.

                            // Save DB-Return into variables

                            while (reader.Read())
                            {
                                Usernametmp = reader.GetString(reader.GetOrdinal("UserName"));
                                FirstNametmp = reader.GetString(reader.GetOrdinal("FirstName"));
                                LastNametmp = reader.GetString(reader.GetOrdinal("LastName"));
                                Emailtmp = reader.GetString(reader.GetOrdinal("Email"));

                                if (reader.IsDBNull(reader.GetOrdinal("ShiftGroupID")))
                                //Test, ob ID NULL, wenn ja ID = 0
                                {
                                    ShiftGroupIDtmp = 0;
                                }
                                else
                                {
                                    ShiftGroupIDtmp = reader.GetInt32(reader.GetOrdinal("ShiftGroupID"));
                                }

                                RoleName = "Admnistrator";
                                ShiftGroupPartnerName = "Tim Nicolaisen";

                                DivisionIDtmp = reader.GetInt32(reader.GetOrdinal("DivisionID"));
                                emp = new EmployeeDetailsViewItem(Idtmp, Usernametmp, FirstNametmp,
                                LastNametmp, Emailtmp, RoleName, ShiftGroupPartnerName, "");

                            }
                        }
                        else
                        {

                        }

                    }

                }
            }
        }
Esempio n. 4
0
        public EmployeeDetailsViewItem SelectEmployeebyDetailsById(string id)
        {
            EmployeeDetailsViewItem emp;
            string Idtmp = "";
            string Usernametmp = "";
            string FirstNametmp = "";
            string LastNametmp = "";
            string Emailtmp = "";
            string RoleName = "";
            string ShiftGroupPartnerId = "";
            string ShiftGroupPartnerName = "";
            string DivisonName = "";
            int ShiftGroupIDtmp = 0;
            int DivisionIDtmp = 0;

            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {
                string sqlStatement =
                    "SELECT [Id], [UserName], [FirstName], [LastName], [Email], [ShiftGroupID], [DivisionID] FROM dbo.AspNetUsers WHERE Id='" + id + "'";
                using (SqlCommand cmd = new SqlCommand(sqlStatement, connection))
                {
                    cmd.Parameters.AddWithValue("EmployeeID", id);
                    connection.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        // Check if the reader has any rows at all before starting to read.
                        if (reader.HasRows)
                        {

                            while (reader.Read())
                            {
                                Usernametmp = reader.GetString(reader.GetOrdinal("UserName"));
                                FirstNametmp = reader.GetString(reader.GetOrdinal("FirstName"));
                                LastNametmp = reader.GetString(reader.GetOrdinal("LastName"));
                                Emailtmp = reader.GetString(reader.GetOrdinal("Email"));

                                if (reader.IsDBNull(reader.GetOrdinal("ShiftGroupID")))
                                //Test, ob ID NULL, wenn ja ID = 0
                                {
                                    ShiftGroupIDtmp = 0;
                                }
                                else
                                {
                                    ShiftGroupIDtmp = reader.GetInt32(reader.GetOrdinal("ShiftGroupID"));
                                }

                                RoleName = SelectRole(id);
                                ShiftGroupPartnerId= SelectShiftPartner(id);

                                if (ShiftGroupPartnerId == null)
                                {
                                    ShiftGroupPartnerName = "Keine Schichtgruppe";
                                }
                                else
                                {
                                    ShiftGroupPartnerName = SelectEmployeeFullName(ShiftGroupPartnerId);
                                }

                                DivisionIDtmp = reader.GetInt32(reader.GetOrdinal("DivisionID"));
                                emp = new EmployeeDetailsViewItem(Idtmp, Usernametmp, FirstNametmp,
                                    LastNametmp, Emailtmp, RoleName, ShiftGroupPartnerName, "");
                                return emp;
                            }
                        }
                        else
                        {
                            return null;
                        }

                    }
                    return null;
                }
            }
        }