Esempio n. 1
0
        private int Person_Add(string organizationUnitID, string Department, string FirstName, string LastName, string Mobile, string Email, string Status, string UserID, string RoleID, string pictureName = null)
        {
            int    rec       = 0;
            string pictureID = null;

            if (pictureName != null)
            {
                var pictureObject = new Digimaker.Content.Picture();
                var sizeArray     = GetPictureSizes();
                var directory     = ConfigurationManager.AppSettings["RestPictureUploadFolder"];
                var resultID      = pictureObject.SavePicture(sizeArray, directory, pictureName, pictureName, "", "", "",
                                                              int.Parse(ConfigurationManager.AppSettings["RestPictureCategory"]));
                if (resultID != -1)
                {
                    foreach (Digimaker.Schemas.Content.PictureData.PicturePropertyRow propertyRow in PictureHandler.GetDataOnPictureMainid(resultID, new int[3] {
                        0, 1, 4
                    }).PictureProperty.Rows)
                    {
                        if (propertyRow.Comment == "Thumbnail")
                        {
                            pictureID = propertyRow.PicturePropertyID.ToString();
                            break;
                        }
                    }
                }
            }
            String strConn = Digimaker.Config.ConnectionString;

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                try
                {
                    //var list = lstEmp.Where(item => lstEmp. == item.ItemCode);
                    //INSERT INTO dbo.Person (GivenName, FamilyName, DisplayName, LoginName, PasswordHash, PasswordSalt, CanReceiveHTMLMail, Email,Custom1)
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("[InsUpd_SericeToDigimakerEmployees]", conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@GivenName", FirstName);
                    cmd.Parameters.AddWithValue("@FamilyName", LastName);

                    cmd.Parameters.AddWithValue("@DisplayName", FirstName + " " + LastName);

                    cmd.Parameters.AddWithValue("@LoginName", UserID);
                    cmd.Parameters.AddWithValue("@PasswordHash", DateTime.Now.ToString() + @"$%$%^^");
                    cmd.Parameters.AddWithValue("@Email", Email);
                    cmd.Parameters.AddWithValue("@EmployeeNo", UserID);
                    cmd.Parameters.AddWithValue("@MobilePhone", Mobile);
                    if (pictureID != null)
                    {
                        cmd.Parameters.AddWithValue("@PictureID", Convert.ToInt32(pictureID));
                    }
                    cmd.Parameters.AddWithValue("@RoleID", Convert.ToInt32(RoleID));

                    cmd.Parameters.AddWithValue("@OrganizationUnitID", Convert.ToInt32(organizationUnitID));
                    cmd.Parameters.Add("@PersonNumber", SqlDbType.Int).Direction = ParameterDirection.Output;
                    // cmd.Parameters.Add("@NewId", SqlDbType.Int).Direction = ParameterDirection.Output;

                    rec = cmd.ExecuteNonQuery();
                    rec = Convert.ToInt32(cmd.Parameters["@PersonNumber"].Value);
                }
                finally
                {
                    if (conn != null && conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            return(rec);
        }
Esempio n. 2
0
        public string UpdateUsers(string UserID, string OrganizationNumber = null,
                                  string Department      = null,
                                  string FirstName       = null,
                                  string LastName        = null,
                                  string Mobile          = null,
                                  string Email           = null,
                                  string Status          = null,
                                  string AccessToBooking = null,
                                  string JPGPicture      = null)
        {
            var result = string.Empty;

            string pictureName = null;

            if (JPGPicture != null && JPGPicture != "")
            {
                pictureName = OrganizationNumber + "-" + FirstName + "-" + LastName + ".jpg";
                var fullPath = ConfigurationManager.AppSettings["RestPictureUploadFolder"] + @"\" + pictureName;
                var bytes    = Convert.FromBase64String(JPGPicture);
                try
                {
                    File.WriteAllBytes(fullPath, bytes);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            try
            {
                if (CheckUserExist(UserID)) //if exists
                {
                    if (AccessToBooking.Equals("1"))
                    {
                        //update role for booking
                        DataSet dsInDatabase = CheckUserPresentInDatabase(UserID);
                        string  PersonID     = dsInDatabase.Tables[0].Rows[0]["PersonID"].ToString();

                        UpdateUserRoleInDatabase(PersonID, Digimaker.Config.Custom.AppSettings["Role_AccessToBooking"].ToString(), 1);
                        result = "10: access to booking enabled.";
                    }
                    else if (AccessToBooking.Equals("0"))
                    {
                        //update
                        DataSet dsInDatabase = CheckUserPresentInDatabase(UserID);
                        string  PersonID     = dsInDatabase.Tables[0].Rows[0]["PersonID"].ToString();

                        UpdateUserRoleInDatabase(PersonID, Digimaker.Config.Custom.AppSettings["Role_AccessToBooking"].ToString(), 2);
                        result = "12: access to booking disabled.";
                    }

                    //Update user profile
                    var personData = PersonHandler.GetPersonData(UserID);
                    var row        = personData.Tables[0].Rows[0];

                    if (FirstName != null)
                    {
                        row["GivenName"] = FirstName;
                    }

                    if (LastName != null)
                    {
                        row["FamilyName"] = LastName;
                    }

                    if (FirstName != null || LastName != null)
                    {
                        row["DisplayName"] = FirstName + " " + LastName;
                    }

                    if (Department != null)
                    {
                        //todo: support this
                    }

                    if (Mobile != null)
                    {
                        row["MobilePhone"] = Mobile;
                    }

                    if (Email != null)
                    {
                        row["Email"] = Email;
                    }
                    if (Status == "Active" || Status == "active")
                    {
                        row["Status"] = "0";
                    }
                    else
                    {
                        //row["Status"] = "1";
                        row["Custom2"] = "hide";
                    }

                    if (pictureName != null)
                    {
                        //upload
                        var pictureID     = row["PictureID"].ToString();
                        var pictureObject = new Digimaker.Content.Picture();
                        var sizeArray     = GetPictureSizes();
                        var directory     = ConfigurationManager.AppSettings["RestPictureUploadFolder"];
                        if (pictureID != "")
                        {
                            var pictureProperty = (Digimaker.Schemas.Content.PictureData.PicturePropertyRow)PictureHandler.GetData(int.Parse(pictureID), new int[3] {
                                1, 2, 4
                            }).PictureProperty.Rows[0];
                            Picture.DeleteMain(pictureProperty.PictureMainID);
                            result += "Picture removed.";
                        }
                        var resultID = pictureObject.SavePicture(sizeArray, directory, pictureName, pictureName, "", "", "",
                                                                 int.Parse(ConfigurationManager.AppSettings["RestPictureCategory"]));
                        if (resultID != -1)
                        {
                            foreach (Digimaker.Schemas.Content.PictureData.PicturePropertyRow propertyRow in PictureHandler.GetDataOnPictureMainid(resultID, new int[3] {
                                1, 2, 4
                            }).PictureProperty.Rows)
                            {
                                if (propertyRow.IsDefault)
                                {
                                    row["PictureID"] = propertyRow.PicturePropertyID.ToString();
                                    break;
                                }
                            }
                            result += "Picture added.";
                        }
                        else
                        {
                            result += "Picture not added.";
                        }
                    }

                    PersonHandler.Update(personData, Int32.Parse(row["PersonID"].ToString()));

                    //Update User Organization In Database
                    DataSet dsInDatabase1 = CheckUserPresentInDatabase(UserID);
                    string  PersonID1     = dsInDatabase1.Tables[0].Rows[0]["PersonID"].ToString();
                    UpdateUserOrganizationInDatabase(PersonID1, OrganizationNumber, 1);

                    result = "13: user profile is updated. " + result;
                }
                else if (Email != null)  //If not exists, create user(need email).
                {
                    var organizationUnitID = CheckOrganizationNumber(OrganizationNumber);
                    if (organizationUnitID != 0)
                    {
                        //Create user
                        //AddActor(OrganizationNumber, Department, FirstName, LastName, Mobile, Email, Status, UserID);
                        Person_Add(organizationUnitID.ToString(), Department, FirstName, LastName, Mobile, Email, Status, UserID, Digimaker.Config.Custom.AppSettings["Role_AccessToBooking"].ToString(), pictureName);
                        result = "11: user created.";
                    }
                    else
                    {
                        result = "01: organization was not found.";
                    }
                }
                else
                {
                    result = "02";
                }
            }
            catch (Exception ex)
            {
                result = ex.ToString(); //todo: log it
            }

            return(result);
        }