Пример #1
0
        public static int CreateUser(string name, string surname, string email, string password, string country, string colour, DateTime birthday, string cellNumber, string comments)
        {
            if (string.IsNullOrEmpty(colour))
            {
                colour = "none";
            }
            if (string.IsNullOrEmpty(comments))
            {
                comments = "none";
            }
            UserDetailsCaptureModelDB data = new UserDetailsCaptureModelDB
            {
                Name            = name,
                Surname         = surname,
                Email           = email,
                Password        = password,
                Country         = country,
                FavouriteColour = colour,
                Birthday        = birthday,
                CellphoneNumber = cellNumber,
                Comments        = comments
            };

            string sql = @"INSERT INTO [UserDetailsCapture].[dbo].[tblUser]
                                  ([Name]
                                 ,[Surname]
                                 ,[Email]
                                 ,[Password]
                                 ,[Country]
                                 ,[FavouriteColour]
                                 ,[Birthday]
                                 ,[CellphoneNumber]
                                 ,[Comments])
                              values 
                                 (
                                   @Name 
                                   ,@Surname
                                   ,@Email
                                   ,@Password
                                   ,@Country
                                   ,@FavouriteColour
                                   ,@Birthday
                                   ,@CellphoneNumber
                                   ,@Comments
                                 ); SELECT SCOPE_IDENTITY()";

            Task <int> lastID = SqlDataAccess.SaveDataAsync(sql, data);

            int id = lastID.Result;

            return(id);
        }
Пример #2
0
        /// <returns>The <see cref="int"/>.</returns>
        public static int UpdateUser(int id, string name, string surname, string email, string password, string country, string colour, DateTime birthday, string cellNumber, string comments)
        {
            if (string.IsNullOrEmpty(colour))
            {
                colour = "none";
            }
            if (string.IsNullOrEmpty(comments))
            {
                comments = "none";
            }

            UserDetailsCaptureModelDB data = new UserDetailsCaptureModelDB
            {
                Name            = name,
                Surname         = surname,
                Email           = email,
                Password        = password,
                Country         = country,
                FavouriteColour = colour,
                Birthday        = birthday,
                CellphoneNumber = cellNumber,
                Comments        = comments
            };

            string sql = string.Format
                             (@"UPDATE [UserDetailsCapture].[dbo].[tblUser]
                       SET [Name] = '{0}'
                          ,[Surname] = '{1}'
                          ,[Email] = '{2}'
                          ,[Password] = '{3}'
                          ,[Country] = '{4}'
                          ,[FavouriteColour] = '{5}'
                          ,[Birthday] = '{6}'
                          ,[CellphoneNumber] = '{7}'
                          ,[Comments] = '{8}'
                     WHERE id ='" + id + "'", data.Name, data.Surname, data.Email, data.Password,
                             data.Country, data.FavouriteColour, data.Birthday, data.CellphoneNumber, data.Comments);

            int rowsAffected = SqlDataAccess.UpdateData(sql, data);

            return(rowsAffected);
        }